Commit bc91225ec616be7f104e3d210a2e6fe901b224b7
Committed by
Michel Felipe

1 parent
3d2172f3
Exists in
master
and in
7 other branches
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
@@ -113,9 +113,9 @@ export class EnvironmentContent { | @@ -113,9 +113,9 @@ export class EnvironmentContent { | ||
113 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, | 113 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, |
114 | MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, | 114 | MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, |
115 | LoginBlockComponent, CustomContentComponent, PermissionDirective, SearchFormComponent, SearchComponent, | 115 | LoginBlockComponent, CustomContentComponent, PermissionDirective, SearchFormComponent, SearchComponent, |
116 | - PersonTagsPluginInterestsBlockComponent, TagsBlockComponent, RecentActivitiesPluginActivitiesBlockComponent, BlockComponent | 116 | + PersonTagsPluginInterestsBlockComponent, TagsBlockComponent, RecentActivitiesPluginActivitiesBlockComponent, BlockComponent, RegisterComponent |
117 | ].concat(plugins.mainComponents).concat(plugins.hotspots), | 117 | ].concat(plugins.mainComponents).concat(plugins.hotspots), |
118 | - providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, | 118 | + providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, RegisterService, |
119 | "ngAnimate", "ngCookies", "ngStorage", "ngTouch", | 119 | "ngAnimate", "ngCookies", "ngStorage", "ngTouch", |
120 | "ngSanitize", "ngMessages", "ngAria", "restangular", | 120 | "ngSanitize", "ngMessages", "ngAria", "restangular", |
121 | "ui.router", "ui.bootstrap", "toastr", "ngCkeditor", | 121 | "ui.router", "ui.bootstrap", "toastr", "ngCkeditor", |