Guest User

Untitled

a guest
Jan 5th, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. class App extends Component{
  2. constructor(){
  3. super();
  4. this.state = { page:1 , signupLogin: 0, logged: false, auth: false, err: 0};
  5. this.user = { username: '', avatar: ''};
  6. this.demo = { username: 'Rounak Polley',email: 'abc@def.ghi', password: 'ijkl'};
  7. this.err = { no: 0 };
  8. }
  9.  
  10. error(val){
  11. this.state.err = val;
  12. //this.setState({err: val}, function(){console.log("error in app.js - "+this.state.err);});
  13. /*
  14. if(val === 1) {alert("You have entered an invalid email address!"); }
  15. else if(val ===2) {alert("Whoops! We couldn’t find an account for that email address and password."); }
  16. else if(val === 3) {alert("All fields are required!"); }
  17. */
  18. }
  19.  
  20.  
  21.  
  22. signup = (newUser) => {
  23. console.log(newUser);
  24. if((newUser.username==='')||(newUser.email==='')||(newUser.password==='')){
  25. this.error(3); console.log("error in app.js - "+this.state.err);
  26. }
  27. else if(!this.ValidateEmail(newUser.email)){
  28. this.error(1); console.log("error in app.js - "+this.state.err);
  29. }
  30. else{
  31. //---// save data
  32. console.log('saved new-user credentials');
  33. //goto login page (values are already copied)
  34. this.setState({signupLogin: 1});
  35. }
  36. };
  37.  
  38. login = (authUser) => {
  39. console.log(authUser);
  40. //error : 1 wrong email format
  41. //---// authenticate user set this.state.auth : true
  42. if((authUser.email === this.demo.email) && (authUser.password === this.demo.password)){
  43. this.state.auth = true;
  44. this.user.username = this.demo.username;
  45. }
  46. else{
  47. //error : 2 wrong username/password
  48. //this.setState({err: 2}); not working why?
  49. //console.log("error in app.js - "+this.state.err);
  50. this.error(2);
  51. console.log("error in app.js - "+this.state.err);
  52. }
  53. if(this.state.auth){
  54. console.log('authenticated user');
  55. this.setState({logged: true});
  56. //get user name and other data and populate the 'this.user'
  57.  
  58. //page 2
  59. //this.setState({page: 2});
  60. }
  61. };
  62.  
  63. logout(){ this.setState({logged: false, signupLogin: 1}); }
  64. render(){
  65. return(
  66. <div className="App">
  67. <MuiThemeProvider muiTheme={muiTheme}>
  68. <SplitWise page={this.state.page}
  69. onTitleClick={this.onTitleClick.bind(this)} signupLogin={this.state.signupLogin}
  70. signupPage={this.signupPage.bind(this)} loginPage={this.loginPage.bind(this)}
  71. signup={this.signup.bind(this)} login={this.login.bind(this)}
  72. logged={this.state.logged} username={this.user.username}
  73. logout={this.logout.bind(this)} err={this.state.err}
  74. />
  75. </MuiThemeProvider>
  76. </div>
  77. );
  78. }
  79. }
Add Comment
Please, Sign In to add comment