| Jeremy Mordkoff | e29efc3 | 2016-09-07 18:59:17 -0400 | [diff] [blame] | 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 | let rw = require('utils/rw.js'); |
| 23 | class LoginScreen extends React.Component{ |
| 24 | constructor(props) { |
| 25 | super(props); |
| 26 | var API_SERVER = rw.getSearchParams(window.location).api_server; |
| 27 | if (!API_SERVER) { |
| 28 | window.location.href = "//" + window.location.host + '/index.html?api_server=' + window.location.protocol + '//localhost'; |
| 29 | } |
| 30 | this.state = { |
| 31 | username: '', |
| 32 | password: '' |
| 33 | }; |
| 34 | |
| 35 | } |
| 36 | updateValue = (e) => { |
| 37 | let state = {}; |
| 38 | state[e.target.name] = e.target.value; |
| 39 | this.setState(state); |
| 40 | } |
| 41 | validate = (e) => { |
| 42 | let self = this; |
| 43 | let state = this.state; |
| 44 | e.preventDefault(); |
| 45 | if (state.username == '' || state.password == '') { |
| 46 | console.log('false'); |
| 47 | return false; |
| 48 | } else { |
| 49 | Utils.setAuthentication(state.username, state.password, function() { |
| 50 | //Returning to previous location disabled post port |
| 51 | // let hash = window.sessionStorage.getItem("locationRefHash") || '#/'; |
| 52 | // if (hash == '#/login') { |
| 53 | // hash = '#/' |
| 54 | // } |
| 55 | // window.location.hash = hash; |
| 56 | self.context.router.push('/'); |
| 57 | }); |
| 58 | |
| 59 | } |
| 60 | } |
| 61 | submitForm = (e) => { |
| 62 | if(e.keyCode == 13){ |
| 63 | this.validate(e); |
| 64 | } |
| 65 | } |
| 66 | render() { |
| 67 | let html; |
| 68 | html = ( |
| 69 | <form className="login-cntnr" autoComplete="on" onKeyUp={this.submitForm}> |
| 70 | <div className="logo"> </div> |
| 71 | <h1 className="riftio">Launchpad Login</h1> |
| 72 | <p> |
| 73 | <input type="text" placeholder="Username" name="username" value={this.state.username} onChange={this.updateValue} autoComplete="username"></input> |
| 74 | </p> |
| 75 | <p> |
| 76 | <input type="password" placeholder="Password" name="password" onChange={this.updateValue} value={this.state.password} autoComplete="password"></input> |
| 77 | </p> |
| 78 | <p> |
| 79 | <Button className="sign-in" onClick={this.validate} style={{cursor: 'pointer'}} type="submit" label="Sign In"/> |
| 80 | </p> |
| 81 | </form> |
| 82 | ) |
| 83 | return html; |
| 84 | } |
| 85 | } |
| 86 | LoginScreen.contextTypes = { |
| 87 | router: React.PropTypes.object |
| 88 | }; |
| 89 | |
| 90 | |
| 91 | export default LoginScreen; |