From bc91225ec616be7f104e3d210a2e6fe901b224b7 Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Mon, 30 May 2016 11:36:05 -0300 Subject: [PATCH] Refactor of the account register component to uses service and restangular instead. --- src/app/account/register.component.ts | 13 ++++++------- src/app/account/register.service.ts | 13 +++++++++++++ src/app/main/main.component.ts | 4 ++-- 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/app/account/register.service.ts diff --git a/src/app/account/register.component.ts b/src/app/account/register.component.ts index 6b33d7e..283b341 100644 --- a/src/app/account/register.component.ts +++ b/src/app/account/register.component.ts @@ -1,19 +1,18 @@ -import { Inject, Input, Component, Output, EventEmitter, } from 'ng-forward'; +import { Inject, Input, Component, Output, EventEmitter } from 'ng-forward'; +import { RegisterService } from './register.service'; @Component({ selector: 'noosfero-register', - templateUrl: 'app/account/register-component.html', + templateUrl: 'app/account/register-component.html' }) -@Inject("$http") +@Inject(RegisterService) export class RegisterComponent { - constructor(private $http: ng.IHttpService) { } + constructor(private registerService: RegisterService) { } signup (account: any) { if (account.password === account.passwordConfirmation) { - this.$http.post("http://localhost:3000/api/v1/register", "login="+account.login+"&email="+account.email+"&password="+account.password).then((response) => { - console.log("User " + account.login + " created, please activate your account."); - }); + this.registerService.createAccount(account); } else { alert("Wrong password confirmation."); } diff --git a/src/app/account/register.service.ts b/src/app/account/register.service.ts new file mode 100644 index 0000000..afb19b7 --- /dev/null +++ b/src/app/account/register.service.ts @@ -0,0 +1,13 @@ +import { Injectable, Inject } from "ng-forward"; +import {RestangularService} from "../../lib/ng-noosfero-api/http/restangular_service"; + +@Injectable() +@Inject("Restangular") +export class RegisterService { + + constructor(private Restangular: restangular.IService) { } + + createAccount(user: noosfero.User): ng.IPromise> { + return this.Restangular.customPOST({account: user}, "register", null); + } +} diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 641ffa2..3e4734c 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -113,9 +113,9 @@ export class EnvironmentContent { MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent, StatisticsBlockComponent, LoginBlockComponent, CustomContentComponent, PermissionDirective, SearchFormComponent, SearchComponent, - PersonTagsPluginInterestsBlockComponent, TagsBlockComponent, RecentActivitiesPluginActivitiesBlockComponent, BlockComponent + PersonTagsPluginInterestsBlockComponent, TagsBlockComponent, RecentActivitiesPluginActivitiesBlockComponent, BlockComponent, RegisterComponent ].concat(plugins.mainComponents).concat(plugins.hotspots), - providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, + providers: [AuthService, SessionService, NotificationService, BodyStateClassesService, RegisterService, "ngAnimate", "ngCookies", "ngStorage", "ngTouch", "ngSanitize", "ngMessages", "ngAria", "restangular", "ui.router", "ui.bootstrap", "toastr", "ngCkeditor", -- libgit2 0.21.2