Commit 487015afa8349b2821609fb5ceb21fb297a4cce6
1 parent
72e8222b
Exists in
updated_signup_page
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
22 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
@@ -9,6 +9,7 @@ import {BoxesComponent} from "../layout/boxes/boxes.component"; | @@ -9,6 +9,7 @@ import {BoxesComponent} from "../layout/boxes/boxes.component"; | ||
9 | import {BlockComponent} from "../layout/blocks/block.component"; | 9 | import {BlockComponent} from "../layout/blocks/block.component"; |
10 | import {EnvironmentComponent} from "../environment/environment.component"; | 10 | import {EnvironmentComponent} from "../environment/environment.component"; |
11 | import {RegisterComponent} from "../account/register.component"; | 11 | import {RegisterComponent} from "../account/register.component"; |
12 | +import {RegisterService} from "../account/register.service"; | ||
12 | import {EnvironmentHomeComponent} from "../environment/environment-home.component"; | 13 | import {EnvironmentHomeComponent} from "../environment/environment-home.component"; |
13 | import {PeopleBlockComponent} from "../layout/blocks/people/people-block.component"; | 14 | import {PeopleBlockComponent} from "../layout/blocks/people/people-block.component"; |
14 | import {DisplayContentBlockComponent} from "../layout/blocks/display-content/display-content-block.component"; | 15 | import {DisplayContentBlockComponent} from "../layout/blocks/display-content/display-content-block.component"; |
@@ -101,10 +102,10 @@ export class EnvironmentContent { | @@ -101,10 +102,10 @@ export class EnvironmentContent { | ||
101 | LinkListBlockComponent, CommunitiesBlockComponent, HtmlEditorComponent, | 102 | LinkListBlockComponent, CommunitiesBlockComponent, HtmlEditorComponent, |
102 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, | 103 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, |
103 | MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, | 104 | MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, |
104 | - LoginBlockComponent, TagsBlockComponent | 105 | + LoginBlockComponent, TagsBlockComponent, RegisterComponent |
105 | ].concat(plugins.mainComponents).concat(plugins.hotspots), | 106 | ].concat(plugins.mainComponents).concat(plugins.hotspots), |
106 | 107 | ||
107 | - providers: [AuthService, SessionService, NotificationService, BodyStateClassesService] | 108 | + providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, RegisterService] |
108 | }) | 109 | }) |
109 | @StateConfig([ | 110 | @StateConfig([ |
110 | { | 111 | { |