register.component.ts
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Inject, Input, Component, Output, EventEmitter, provide } from 'ng-forward';
import { RegisterService } from "./../../lib/ng-noosfero-api/http/register.service";
import { NotificationService } from "./../shared/services/notification.service";
import { EnvironmentService } from "../../lib/ng-noosfero-api/http/environment.service";
import { RegisterController } from "./register.controller";
import { IModalComponent } from "../shared/components/interfaces";
@Component({
selector: 'noosfero-register',
templateUrl: 'app/account/register-component.html',
providers: [
provide('registerService', { useClass: RegisterService })
]
})
@Inject('$state', '$uibModal', '$scope', RegisterService, NotificationService, EnvironmentService)
export class RegisterComponent {
@Input() account: any;
environment: noosfero.Environment;
modalInstance: ng.ui.bootstrap.IModalServiceInstance;
constructor(
private $state: ng.ui.IStateService,
private $uibModal: ng.ui.bootstrap.IModalService,
private $scope: ng.IScope,
public registerService: RegisterService,
private notificationService: NotificationService,
private environmentService: EnvironmentService,
) {
this.account = {};
this.environment = environmentService.getCurrentEnvironment();
}
signup() {
if (this.account.password === this.account.password_confirmation) {
this.registerService.createAccount(this.account).then((response) => {
if (response.status === 201) {
this.$state.transitionTo('main.environment');
this.notificationService.success({ title: "account.register.success.title", message: "account.register.success.message" });
} else {
throw new Error('Invalid attributes');
}
});
} else {
this.notificationService.error({ message: "account.register.passwordConfirmation.failed" });
}
}
isInvalid(field: Object): Object {
return { 'has-error': field['$touched'] && field['$invalid'] };
}
openTerms() {
this.modalInstance = this.$uibModal.open({
templateUrl: 'app/account/register-terms.html',
size: 'lg',
controller: RegisterController,
controllerAs: 'vm',
bindToController: true,
scope: this.$scope
});
}
}