RIFT-15726 - optimize download size -> lodash usage in UI
[osm/UI.git] / skyquake / framework / widgets / login / login.jsx
1 /*
2  * 
3  *   Copyright 2016 RIFT.IO Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  */
18 import React from 'react';
19 import Utils from 'utils/utils.js';
20 import Button from 'widgets/button/rw.button.js';
21 import './login.scss'
22 import rw from 'utils/rw.js';
23
24 class LoginScreen extends React.Component{
25   constructor(props) {
26     super(props);
27     var API_SERVER =  rw.getSearchParams(window.location).api_server;
28     if (!API_SERVER) {
29       window.location.href = "//" + window.location.host + '/index.html?api_server=' + window.location.protocol + '//localhost';
30     }
31     this.state = {
32       username: '',
33       password: ''
34     };
35
36   }
37   updateValue = (e) => {
38     let state = {};
39     state[e.target.name] = e.target.value;
40     this.setState(state);
41   }
42   validate = (e) => {
43     let self = this;
44     let state = this.state;
45     e.preventDefault();
46     if (state.username == '' || state.password == '') {
47       console.log('false');
48       return false;
49     } else {
50       Utils.setAuthentication(state.username, state.password, function() {
51         //Returning to previous location disabled post port
52         //  let hash = window.sessionStorage.getItem("locationRefHash") || '#/';
53         //   if (hash == '#/login') {
54         //     hash = '#/'
55         //   }
56         // window.location.hash = hash;
57         self.context.router.push('/');
58       });
59
60     }
61   }
62   submitForm = (e) => {
63       if(e.keyCode == 13){
64         this.validate(e);
65       }
66   }
67   render() {
68     let html;
69     html = (
70       <form className="login-cntnr" autoComplete="on" onKeyUp={this.submitForm}>
71         <div className="logo"> </div>
72         <h1 className="riftio">Launchpad Login</h1>
73         <p>
74             <input type="text" placeholder="Username" name="username" value={this.state.username} onChange={this.updateValue} autoComplete="username"></input>
75         </p>
76         <p>
77             <input type="password" placeholder="Password" name="password" onChange={this.updateValue} value={this.state.password} autoComplete="password"></input>
78         </p>
79         <p>
80            <Button className="sign-in" onClick={this.validate}  style={{cursor: 'pointer'}} type="submit" label="Sign In"/>
81         </p>
82       </form>
83     )
84     return html;
85   }
86 }
87 LoginScreen.contextTypes = {
88     router: React.PropTypes.object
89   };
90
91
92 export default LoginScreen;