2015-02-17 21:58:39 +01:00
|
|
|
|
var React = require("react");
|
2015-03-01 16:43:28 +01:00
|
|
|
|
var NavigationActions = require('../../actions/navigationActions');
|
2015-03-02 07:49:36 +01:00
|
|
|
|
var UserActions = require('../../actions/userActions');
|
2015-03-01 16:43:28 +01:00
|
|
|
|
var Router = require('react-router');
|
|
|
|
|
|
var Link = Router.Link;
|
2015-03-02 07:49:36 +01:00
|
|
|
|
var RibicaValidationMixin = require('../../components/shared/mixins/ribicaValidationMixin');
|
|
|
|
|
|
var ValidationUtils = require('../../utils/validation.js');
|
|
|
|
|
|
var LoginModel = require('../../models/login');
|
|
|
|
|
|
var UserStore = require('../../stores/userStore');
|
|
|
|
|
|
|
2015-02-17 21:58:39 +01:00
|
|
|
|
var Login = React.createClass({
|
2015-03-02 07:49:36 +01:00
|
|
|
|
mixins: [RibicaValidationMixin],
|
|
|
|
|
|
componentDidMount:function() {
|
|
|
|
|
|
UserStore.addChangeListener(this.onUserStoreChange);
|
|
|
|
|
|
},
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
|
|
UserStore.removeChangeListener(this.onUserStoreChange);
|
|
|
|
|
|
},
|
|
|
|
|
|
onUserStoreChange: function() {
|
2015-03-03 19:11:38 +01:00
|
|
|
|
if(this.isMounted()) {
|
|
|
|
|
|
var loginState = UserStore.getLoginState();
|
2015-03-02 07:49:36 +01:00
|
|
|
|
this.setState({login: loginState});
|
2015-03-03 19:11:38 +01:00
|
|
|
|
if (loginState.loggedIn) {
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
|
NavigationActions.goToHome();
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
}
|
2015-03-02 07:49:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
email: '',
|
|
|
|
|
|
password: '',
|
|
|
|
|
|
login: UserStore.getLoginState()
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
validations: {
|
|
|
|
|
|
email:function(value) {
|
|
|
|
|
|
|
|
|
|
|
|
if(!ValidationUtils.isValidEmail(value)) {
|
|
|
|
|
|
return ['Neispravna email adresa.'];
|
|
|
|
|
|
}
|
|
|
|
|
|
return [];
|
|
|
|
|
|
},
|
|
|
|
|
|
password: function(value) {
|
|
|
|
|
|
if(!ValidationUtils.isValidRequired(value)) {
|
|
|
|
|
|
return ["Šifra je obavezna."];
|
|
|
|
|
|
}
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
renderErrorMessage: function(message){
|
|
|
|
|
|
return (<div className='error-message'>{message}</div>)
|
|
|
|
|
|
},
|
2015-03-28 14:10:56 +01:00
|
|
|
|
onLoginClick: function(e) {
|
|
|
|
|
|
this.doLogin();
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
},
|
|
|
|
|
|
doLogin: function() {
|
2015-03-02 07:49:36 +01:00
|
|
|
|
if(this.validate()) {
|
|
|
|
|
|
var loginInfo = new LoginModel({
|
|
|
|
|
|
email: this.state.email,
|
|
|
|
|
|
password: this.state.password
|
|
|
|
|
|
});
|
2015-03-01 16:43:28 +01:00
|
|
|
|
|
2015-03-02 07:49:36 +01:00
|
|
|
|
UserActions.userLogin(loginInfo);
|
|
|
|
|
|
|
2015-03-28 14:10:56 +01:00
|
|
|
|
}
|
2015-03-02 07:49:36 +01:00
|
|
|
|
},
|
|
|
|
|
|
renderLoginFailure: function() {
|
|
|
|
|
|
|
|
|
|
|
|
var loginState = this.state.login;
|
|
|
|
|
|
if(!loginState.loggedIn) {
|
|
|
|
|
|
return (<div>{loginState.error}</div>)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (<div></div>)
|
|
|
|
|
|
},
|
2015-03-28 14:10:56 +01:00
|
|
|
|
onKeyPress: function(e) {
|
|
|
|
|
|
var enterKeyCode = 13;
|
|
|
|
|
|
if(e.which == enterKeyCode) {
|
|
|
|
|
|
this.doLogin();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2015-03-01 16:43:28 +01:00
|
|
|
|
render : function() {
|
2015-04-19 23:07:03 +02:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="col-lg-4 col-md-6 col-sm-8 col-xs-10 col-centered" style={{height: 500}}>
|
|
|
|
|
|
|
|
|
|
|
|
<h1 style={{paddingTop: 40}} className="text-center">Prijava</h1>
|
|
|
|
|
|
<br />
|
|
|
|
|
|
{this.renderLoginFailure()}
|
|
|
|
|
|
|
|
|
|
|
|
<form className>
|
|
|
|
|
|
<div className="form-group col-lg-12 col-md-12">
|
|
|
|
|
|
<input style={{marginBottom: 8}} type="text" className="form-control" onKeyPress={this.onKeyPress} onChange={this.handleChange('email')} placeholder="Email adresa" />
|
|
|
|
|
|
{this.getValidationMessages('email').map(this.renderErrorMessage)}
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="form-group col-lg-12 col-md-12">
|
|
|
|
|
|
<input style={{marginBottom: 8}} type="password" onKeyPress={this.onKeyPress} onChange={this.handleChange('password')} className="form-control" placeholder="Šifra" />
|
|
|
|
|
|
{this.getValidationMessages('password').map(this.renderErrorMessage)}
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
2015-05-27 13:58:44 +02:00
|
|
|
|
<input style={{color: 'white', fontWeight: 'bold', height: 44}} type="submit" onClick={this.onLoginClick} className=" mybutton center-block col-md-8 col-sm-8 col-xs-8 col-sm-push-2 col-xs-push-2 col-md-push-2" defaultValue="PRIJAVA" />
|
2015-04-19 23:07:03 +02:00
|
|
|
|
</form>
|
|
|
|
|
|
<div className="text-center col-lg-12">
|
|
|
|
|
|
<h4>Niste registrovani? <Link to="registracija"><span>Registrujte se</span></Link></h4>
|
|
|
|
|
|
</div>
|
2015-03-02 07:49:36 +01:00
|
|
|
|
</div>);
|
2015-03-01 16:43:28 +01:00
|
|
|
|
}
|
2015-03-02 07:49:36 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2015-02-17 21:58:39 +01:00
|
|
|
|
module.exports = Login;
|