Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var SHA1 = require("Crypto");
  2.  
  3. class User {
  4.  
  5.     private id: number;
  6.     private username: string;
  7.     private password: string;
  8.  
  9.     constructor(username?: string, password?: string) {
  10.         if (username && password) {
  11.             this.username = username;
  12.             this.password = password;
  13.         }
  14.     }
  15.  
  16.     Create(username, password, mail) {
  17.         var user = Database.CreateUser(username, password, mail);
  18.         return user;
  19.     }
  20.  
  21.     Connect(crypted) {
  22.         if (!crypted) {
  23.             this.password = SHA1(this.password);
  24.         }
  25.         var users = Database.Search("users", { "username": this.username, "password": this.password });
  26.         if (users.length >= 1) {
  27.             if (users.length > 1) {
  28.                 console.log("Multiple Users Find, First Take");
  29.             }
  30.             this.id = users[0].id;
  31.         } else {
  32.             console.log("No User Find with username " + this.username);
  33.             return 0;
  34.         }
  35.     }
  36.  
  37.     GetId() {
  38.         return this.id;
  39.     }
  40.  
  41.     GetUsername() {
  42.         return this.username;
  43.     }
  44. }
  45.  
  46. module.exports = User;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement