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 | 4 | @Component({ |
| 4 | 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 | 10 | export class RegisterComponent { |
| 10 | - constructor(private $http: ng.IHttpService) { } | |
| 11 | + constructor(private registerService: RegisterService) { } | |
| 11 | 12 | |
| 12 | 13 | signup (account: any) { |
| 13 | 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 | 16 | } else { |
| 18 | 17 | alert("Wrong password confirmation."); |
| 19 | 18 | } | ... | ... |
| ... | ... | @@ -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 | 113 | MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, |
| 114 | 114 | MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, |
| 115 | 115 | LoginBlockComponent, CustomContentComponent, PermissionDirective, SearchFormComponent, SearchComponent, |
| 116 | - PersonTagsPluginInterestsBlockComponent, TagsBlockComponent, RecentActivitiesPluginActivitiesBlockComponent, BlockComponent | |
| 116 | + PersonTagsPluginInterestsBlockComponent, TagsBlockComponent, RecentActivitiesPluginActivitiesBlockComponent, BlockComponent, RegisterComponent | |
| 117 | 117 | ].concat(plugins.mainComponents).concat(plugins.hotspots), |
| 118 | - providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, | |
| 118 | + providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, RegisterService, | |
| 119 | 119 | "ngAnimate", "ngCookies", "ngStorage", "ngTouch", |
| 120 | 120 | "ngSanitize", "ngMessages", "ngAria", "restangular", |
| 121 | 121 | "ui.router", "ui.bootstrap", "toastr", "ngCkeditor", | ... | ... |