forked from nutomic/lemmy
parent
009b3b5079
commit
018cbe1fee
4 changed files with 15 additions and 6 deletions
|
@ -2,6 +2,7 @@
|
||||||
name = "server"
|
name = "server"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
authors = ["Dessalines <happydooby@gmail.com>"]
|
authors = ["Dessalines <happydooby@gmail.com>"]
|
||||||
|
autobins = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "lemmy"
|
name = "lemmy"
|
||||||
|
|
|
@ -92,6 +92,7 @@ pub struct Register {
|
||||||
password: String,
|
password: String,
|
||||||
password_verify: String,
|
password_verify: String,
|
||||||
admin: bool,
|
admin: bool,
|
||||||
|
spam_timer: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -789,6 +790,10 @@ impl Perform for Register {
|
||||||
return Err(self.error("Passwords do not match."))?
|
return Err(self.error("Passwords do not match."))?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.spam_timer < 1142 {
|
||||||
|
return Err(self.error("Too fast"))?
|
||||||
|
}
|
||||||
|
|
||||||
if has_slurs(&self.username) {
|
if has_slurs(&self.username) {
|
||||||
return Err(self.error("No slurs"))?
|
return Err(self.error("No slurs"))?
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ interface State {
|
||||||
registerForm: RegisterForm;
|
registerForm: RegisterForm;
|
||||||
loginLoading: boolean;
|
loginLoading: boolean;
|
||||||
registerLoading: boolean;
|
registerLoading: boolean;
|
||||||
spamTimer: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,10 +26,10 @@ export class Login extends Component<any, State> {
|
||||||
password: undefined,
|
password: undefined,
|
||||||
password_verify: undefined,
|
password_verify: undefined,
|
||||||
admin: false,
|
admin: false,
|
||||||
|
spam_timer: undefined,
|
||||||
},
|
},
|
||||||
loginLoading: false,
|
loginLoading: false,
|
||||||
registerLoading: false,
|
registerLoading: false,
|
||||||
spamTimer: new Date().getTime()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props: any, context: any) {
|
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 />
|
<input type="password" value={this.state.registerForm.password_verify} onInput={linkEvent(this, this.handleRegisterPasswordVerifyChange)} class="form-control" required />
|
||||||
</div>
|
</div>
|
||||||
</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="form-group row">
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<button type="submit" class="btn btn-secondary">{this.state.registerLoading ?
|
<button type="submit" class="btn btn-secondary">{this.state.registerLoading ?
|
||||||
|
@ -162,16 +161,19 @@ export class Login extends Component<any, State> {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
let endTimer = new Date().getTime();
|
let endTimer = new Date().getTime();
|
||||||
let elapsed = endTimer - i.state.spamTimer;
|
let elapsed = endTimer - i.state.registerForm.spam_timer;
|
||||||
if (elapsed > 4500) {
|
|
||||||
|
i.state.registerForm.spam_timer = elapsed;
|
||||||
|
if (elapsed > 1142) {
|
||||||
WebSocketService.Instance.register(i.state.registerForm);
|
WebSocketService.Instance.register(i.state.registerForm);
|
||||||
} else {
|
} else {
|
||||||
location.reload(true);
|
window.location.href = "https://github.com/dessalines/lemmy";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRegisterUsernameChange(i: Login, event: any) {
|
handleRegisterUsernameChange(i: Login, event: any) {
|
||||||
i.state.registerForm.username = event.target.value;
|
i.state.registerForm.username = event.target.value;
|
||||||
|
i.state.registerForm.spam_timer = new Date().getTime();
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -330,6 +330,7 @@ export interface RegisterForm {
|
||||||
email?: string;
|
email?: string;
|
||||||
password: string;
|
password: string;
|
||||||
password_verify: string;
|
password_verify: string;
|
||||||
|
spam_timer: number;
|
||||||
admin: boolean;
|
admin: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue