Skip to content

Commit

Permalink
Fixing rust warning.
Browse files Browse the repository at this point in the history
- Fixes LemmyNet#111
  • Loading branch information
dessalines committed Apr 26, 2019
1 parent fba4d37 commit be943f7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "server"
version = "0.0.1"
authors = ["Dessalines <[email protected]>"]
autobins = false

[[bin]]
name = "lemmy"
Expand Down
5 changes: 5 additions & 0 deletions server/src/websocket_server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub struct Register {
password: String,
password_verify: String,
admin: bool,
spam_timer: i64,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -789,6 +790,10 @@ impl Perform for Register {
return Err(self.error("Passwords do not match."))?
}

if self.spam_timer < 1142 {
return Err(self.error("Too fast"))?
}

if has_slurs(&self.username) {
return Err(self.error("No slurs"))?
}
Expand Down
14 changes: 8 additions & 6 deletions ui/src/components/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface State {
registerForm: RegisterForm;
loginLoading: boolean;
registerLoading: boolean;
spamTimer: number;
}


Expand All @@ -27,10 +26,10 @@ export class Login extends Component<any, State> {
password: undefined,
password_verify: undefined,
admin: false,
spam_timer: undefined,
},
loginLoading: false,
registerLoading: false,
spamTimer: new Date().getTime()
}

constructor(props: any, context: any) {
Expand Down Expand Up @@ -126,7 +125,7 @@ export class Login extends Component<any, State> {
<input type="password" value={this.state.registerForm.password_verify} onInput={linkEvent(this, this.handleRegisterPasswordVerifyChange)} class="form-control" required />
</div>
</div>
<input type="hidden" value={this.state.spamTimer} />
<input type="hidden" value={this.state.registerForm.spam_timer} />
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-secondary">{this.state.registerLoading ?
Expand Down Expand Up @@ -162,16 +161,19 @@ export class Login extends Component<any, State> {
event.preventDefault();

let endTimer = new Date().getTime();
let elapsed = endTimer - i.state.spamTimer;
if (elapsed > 4500) {
let elapsed = endTimer - i.state.registerForm.spam_timer;

i.state.registerForm.spam_timer = elapsed;
if (elapsed > 1142) {
WebSocketService.Instance.register(i.state.registerForm);
} else {
location.reload(true);
window.location.href = "https://github.com/dessalines/lemmy";
}
}

handleRegisterUsernameChange(i: Login, event: any) {
i.state.registerForm.username = event.target.value;
i.state.registerForm.spam_timer = new Date().getTime();
i.setState(i.state);
}

Expand Down
1 change: 1 addition & 0 deletions ui/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export interface RegisterForm {
email?: string;
password: string;
password_verify: string;
spam_timer: number;
admin: boolean;
}

Expand Down

0 comments on commit be943f7

Please sign in to comment.