ionic-coreo
Version:
Ionic2 module for integration with Coreo
87 lines • 3.62 kB
JavaScript
;
var core_1 = require('@angular/core');
var email_login_component_template_1 = require('./email-login.component.template');
var login_component_template_1 = require('../login.component.template');
var forms_1 = require('@angular/forms');
var ionic_angular_1 = require('ionic-angular');
var auth_1 = require('../../../auth');
var signup_component_1 = require('../signup/signup.component');
var user_1 = require('../../../user');
var username_confirmation_component_1 = require('../username-confirmation/username-confirmation.component');
var CoreoEmailLoginComponent = (function () {
function CoreoEmailLoginComponent(formBuilder, auth, navCtrl, viewCtrl, navParams, user) {
this.auth = auth;
this.navCtrl = navCtrl;
this.viewCtrl = viewCtrl;
this.navParams = navParams;
this.user = user;
this.loginError = false;
this.isLoggingIn = false;
this.form = formBuilder.group({
email: ['', forms_1.Validators.required],
password: ['', forms_1.Validators.required]
});
this.onSuccess = this.navParams.get('onSuccess');
}
CoreoEmailLoginComponent.prototype.handleSuccess = function () {
this.viewCtrl.dismiss();
this.onSuccess();
};
CoreoEmailLoginComponent.prototype.handleLogin = function (event) {
var _this = this;
var _a = this.form.value, email = _a.email, password = _a.password;
this.isLoggingIn = true;
this.loginError = false;
this.auth.login('basic', { email: email, password: password }).then(function (result) {
if (!_this.user.usernameConfirmed) {
_this.navCtrl.push(username_confirmation_component_1.CoreoUsernameConfirmationComponent, {
onSuccess: function () {
_this.handleSuccess();
}
});
}
else {
_this.handleSuccess();
}
}, function (err) {
_this.isLoggingIn = false;
switch (err.statusCode) {
case 401: {
_this.loginError = err.message === 'Unauthorized' ? 'Please check your username and password.' : err.message;
break;
}
default: {
_this.loginError = 'An error occurred.';
}
}
});
};
CoreoEmailLoginComponent.prototype.gotoSignup = function (event) {
var _this = this;
event.preventDefault();
event.stopImmediatePropagation();
this.navCtrl.push(signup_component_1.CoreoSignupComponent, {
onSuccess: function (email, password) {
_this.form.patchValue({ email: email, password: password });
}
});
};
CoreoEmailLoginComponent.decorators = [
{ type: core_1.Component, args: [{
template: email_login_component_template_1.DEFAULT_TEMPLATE,
styles: [login_component_template_1.SHARED_STYLES]
},] },
];
/** @nocollapse */
CoreoEmailLoginComponent.ctorParameters = function () { return [
{ type: forms_1.FormBuilder, },
{ type: auth_1.CoreoAuth, },
{ type: ionic_angular_1.NavController, },
{ type: ionic_angular_1.ViewController, },
{ type: ionic_angular_1.NavParams, },
{ type: user_1.CoreoUser, },
]; };
return CoreoEmailLoginComponent;
}());
exports.CoreoEmailLoginComponent = CoreoEmailLoginComponent;
//# sourceMappingURL=email-login.component.js.map