daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Dec 6th, 2016 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //UserController.js
  2. class UserController{
  3.     constructor(model, view){
  4.         this.model = model;
  5.         this.view = view;
  6.     }
  7.  
  8.     registerUser(event){
  9.         event.preventDefault();
  10.         let userObject = this.view.getDataFromRegister();
  11.         this.model.registerUser(userObject).then((data) => {
  12.             saveAuthInSession(data);
  13.             showHideMenuLinks();
  14.             showHomeView();
  15.         }).catch((error) =>{
  16.             handleAjaxError(error);
  17.         });
  18.     }
  19.  
  20.     loginUser(event){
  21.         event.preventDefault();
  22.  
  23.         //console.dir(this.view);
  24.        // console.dir(this.model);
  25.        let userObject = this.view.getDataFromLogin();
  26.         this.model.loginUser(userObject).then((data) => {
  27.             saveAuthInSession(data);
  28.             showHideMenuLinks();
  29.             showHomeView();
  30.         }).catch((error) =>{
  31.             handleAjaxError(error);
  32.         });
  33.     }
  34. }
  35.  
  36. UserView.js
  37.  
  38. /**
  39.  * Created by tonch on 04-Dec-16.
  40.  */
  41. class UserView{
  42.     constructor(){
  43.  
  44.     }
  45.  
  46.     getDataFromLogin(){
  47.  
  48.         let username = $('#formLogin input[name=username]').val();
  49.         let password = $('#formLogin input[name=passwd]').val();
  50.  
  51.         if (username.length < 5) {
  52.             showError("Username must consist of at least 5 characters.");
  53.             return;
  54.         }
  55.  
  56.         if (password.length < 5) {
  57.             showError("Password must consist of at least 5 characters.");
  58.             return;
  59.         }
  60.         return  {
  61.             username: username,
  62.             password: password
  63.         };
  64.     }
  65.  
  66.  
  67.    getDataFromRegister(){
  68.  
  69.         let username = $('#formRegister input[name=username]').val();
  70.         let password = $('#formRegister input[name=passwd]').val();
  71.  
  72.         if (username.length < 5) {
  73.             showError("Username must consist of at least 5 characters.");
  74.             return;
  75.         }
  76.  
  77.         if (password.length < 5) {
  78.             showError("Password must consist of at least 5 characters.");
  79.             return;
  80.         }
  81.             return  {
  82.                 username: username,
  83.                 password: password
  84.             };
  85.     }
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top