]> Untitled Git - lemmy.git/commitdiff
Fixing rust warning.
authorDessalines <tyhou13@gmx.com>
Fri, 26 Apr 2019 14:34:04 +0000 (07:34 -0700)
committerDessalines <tyhou13@gmx.com>
Fri, 26 Apr 2019 14:34:04 +0000 (07:34 -0700)
- Fixes #111

server/Cargo.toml
server/src/websocket_server/server.rs
ui/src/components/login.tsx
ui/src/interfaces.ts

index 93bd6acb2b4befa53d3e66902c88e37d192d2975..1daaca663660e9311c7ac49b6fca9a62353df001 100644 (file)
@@ -2,6 +2,7 @@
 name = "server"
 version = "0.0.1"
 authors = ["Dessalines <happydooby@gmail.com>"]
+autobins = false
 
 [[bin]]
 name = "lemmy"
index dbd1be8d58eaebcfba8b8d451904e54e728c9552..d6a9226b2502409f93acf1bffff0b604dbc8ba83 100644 (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"))?
     }
index e6dec2d2e086985692b7787f9c93dfd8aa343a90..0713b77662c9fc923d872a143761a61ec1d185f4 100644 (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);
   }
 
index 68d1b4122a2ca0ff844befcaa4832406b388fcd5..4fa30d188bced72325e6f234bee125d6514cb71b 100644 (file)
@@ -330,6 +330,7 @@ export interface RegisterForm {
   email?: string;
   password: string;
   password_verify: string;
+  spam_timer: number;
   admin: boolean;
 }