Commit b7edb563387cf5b80520a07a4d4b2704f65648e3
Committed by
Michel Felipe

1 parent
207be9ec
Refactor of the account register component to uses service and restangular instead.
Signed-off-by: DylanGuedes <djmgguedes@gmail.com> Signed-off-by: ArthurJahn <stutrzbecher@gmail.com> Signed-off-by: Fábio Teixeira <fabio1079@gmail.com>
Showing
3 changed files
with
21 additions
and
9 deletions
Show diff stats
src/app/account/register.component.ts
1 | -import { Inject, Input, Component, Output, EventEmitter, } from 'ng-forward'; | 1 | +import { Inject, Input, Component, Output, EventEmitter } from 'ng-forward'; |
2 | +import { RegisterService } from './register.service'; | ||
2 | 3 | ||
3 | @Component({ | 4 | @Component({ |
4 | selector: 'noosfero-register', | 5 | selector: 'noosfero-register', |
5 | - templateUrl: 'app/account/register-component.html', | 6 | + templateUrl: 'app/account/register-component.html' |
6 | }) | 7 | }) |
7 | 8 | ||
8 | -@Inject("$http") | 9 | +@Inject(RegisterService) |
9 | export class RegisterComponent { | 10 | export class RegisterComponent { |
10 | - constructor(private $http: ng.IHttpService) { } | 11 | + constructor(private registerService: RegisterService) { } |
11 | 12 | ||
12 | signup (account: any) { | 13 | signup (account: any) { |
13 | if (account.password === account.passwordConfirmation) { | 14 | if (account.password === account.passwordConfirmation) { |
14 | - this.$http.post("http://localhost:3000/api/v1/register", "login="+account.login+"&email="+account.email+"&password="+account.password).then((response) => { | ||
15 | - console.log("User " + account.login + " created, please activate your account."); | ||
16 | - }); | 15 | + this.registerService.createAccount(account); |
17 | } else { | 16 | } else { |
18 | alert("Wrong password confirmation."); | 17 | alert("Wrong password confirmation."); |
19 | } | 18 | } |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +import { Injectable, Inject } from "ng-forward"; | ||
2 | +import {RestangularService} from "../../lib/ng-noosfero-api/http/restangular_service"; | ||
3 | + | ||
4 | +@Injectable() | ||
5 | +@Inject("Restangular") | ||
6 | +export class RegisterService { | ||
7 | + | ||
8 | + constructor(private Restangular: restangular.IService) { } | ||
9 | + | ||
10 | + createAccount(user: noosfero.User): ng.IPromise<noosfero.RestResult<noosfero.User>> { | ||
11 | + return this.Restangular.customPOST({account: user}, "register", null); | ||
12 | + } | ||
13 | +} |
src/app/main/main.component.ts
@@ -108,9 +108,9 @@ export class EnvironmentContent { | @@ -108,9 +108,9 @@ export class EnvironmentContent { | ||
108 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, | 108 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, |
109 | MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, | 109 | MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, |
110 | LoginBlockComponent, CustomContentComponent, PermissionDirective, SearchFormComponent, SearchComponent, | 110 | LoginBlockComponent, CustomContentComponent, PermissionDirective, SearchFormComponent, SearchComponent, |
111 | - PersonTagsPluginInterestsBlockComponent, TagsBlockComponent, RecentActivitiesPluginActivitiesBlockComponent, BlockComponent | 111 | + PersonTagsPluginInterestsBlockComponent, TagsBlockComponent, RecentActivitiesPluginActivitiesBlockComponent, BlockComponent, RegisterComponent |
112 | ].concat(plugins.mainComponents).concat(plugins.hotspots), | 112 | ].concat(plugins.mainComponents).concat(plugins.hotspots), |
113 | - providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, | 113 | + providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, RegisterService, |
114 | "ngAnimate", "ngCookies", "ngStorage", "ngTouch", | 114 | "ngAnimate", "ngCookies", "ngStorage", "ngTouch", |
115 | "ngSanitize", "ngMessages", "ngAria", "restangular", | 115 | "ngSanitize", "ngMessages", "ngAria", "restangular", |
116 | "ui.router", "ui.bootstrap", "toastr", "ngCkeditor", | 116 | "ui.router", "ui.bootstrap", "toastr", "ngCkeditor", |