Fixing rust warning.

- Fixes #111
This commit is contained in:
Dessalines 2019-04-26 07:34:04 -07:00
parent 009b3b5079
commit 018cbe1fee
4 changed files with 15 additions and 6 deletions

View File

@ -2,6 +2,7 @@
name = "server"
version = "0.0.1"
authors = ["Dessalines <happydooby@gmail.com>"]
autobins = false
[[bin]]
name = "lemmy"

View File

@ -92,6 +92,7 @@ pub struct Register {
password: String,
password_verify: String,
admin: bool,
spam_timer: i64,
}
#[derive(Serialize, Deserialize)]
@ -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"))?
}

View File

@ -10,7 +10,6 @@ interface State {
registerForm: RegisterForm;
loginLoading: boolean;
registerLoading: boolean;
spamTimer: number;
}
@ -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) {
@ -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 ?
@ -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);
}

View File

@ -330,6 +330,7 @@ export interface RegisterForm {
email?: string;
password: string;
password_verify: string;
spam_timer: number;
admin: boolean;
}