File

assets/angular/shared/user.service-simple.ts

Description

User related service...

Author: Shilo Banihit

Index

Properties
Methods

Constructor

constructor(http: Http, configService: ConfigService)
Parameters :
Name Type Optional Description
http Http
configService ConfigService

Methods

addLocalUser
addLocalUser(username: any, details: any)
Parameters :
Name Type Optional Description
username any
details any
Returns : any
genKey
genKey(userid: any)
Parameters :
Name Type Optional Description
userid any
Returns : any
genUserKey
genUserKey()
Returns : any
getInfo
getInfo()
Returns : Promise<User>
getUsers
getUsers()
Returns : Promise<[]>
loginLocal
loginLocal(username: string, password: string)
Parameters :
Name Type Optional Description
username string
password string
Returns : Promise<any>
revokeKey
revokeKey(userid: any)
Parameters :
Name Type Optional Description
userid any
Returns : any
revokeUserKey
revokeUserKey()
Returns : any
updateUserDetails
updateUserDetails(userid: any, details: any)
Parameters :
Name Type Optional Description
userid any
details any
Returns : any
updateUserProfile
updateUserProfile(details: any)
Parameters :
Name Type Optional Description
details any
Returns : any

Properties

Protected baseUrl
baseUrl: any
Type : any
Protected config
config: any
Type : any
Protected headers
headers: any
Type : any
import { Injectable, Inject} from '@angular/core';
import { Http, Response, RequestOptions, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import { BaseService } from '../shared/base-service'
import { User, LoginResult, SaveResult } from './user-models'
import { ConfigService } from '../shared/config-service';
/**
 * User related service...
 *
 * Author: <a href='https://github.com/shilob' target='_blank'>Shilo Banihit</a>
 *
 */
@Injectable()
export class UserSimpleService extends BaseService {
  protected baseUrl: any;
  protected config: any;
  protected headers: any;

  constructor (@Inject(Http) http: Http, @Inject(ConfigService) protected configService: ConfigService) {
    super(http, configService);
  }

  getInfo(): Promise<User> {
    return this.http.get(`${this.baseUrl}/user/info`)
    .toPromise()
    .then((res:any) => this.extractData(res, 'user') as User);
  }

  loginLocal(username: string, password: string): Promise<any> {
    console.log(`Loggin in locally using brand: ${this.config.branding}, portal: ${this.config.portal}`);
    return this.http.post(`${this.baseUrl}/user/login_local`, {username: username, password:password, branding:this.config.branding, portal: this.config.portal}, this.getOptionsClient())
    .toPromise()
    .then(this.extractData);
  }

  getUsers() :Promise<User[]> {
    return this.http.get(`${this.brandingAndPortalUrl}/admin/users/get`, this.options)
    .toPromise()
    .then((res:any) => this.extractData(res) as User[]);
  }

  updateUserDetails(userid: any, details: any) {
    return this.http.post(`${this.brandingAndPortalUrl}/admin/users/update`, {userid: userid, details:details}, this.options)
    .toPromise()
    .then((res:any) => this.extractData(res) as SaveResult[]);
  }

  addLocalUser(username: any, details: any) {
    return this.http.post(`${this.brandingAndPortalUrl}/admin/users/newUser`, {username: username, details:details}, this.options)
    .toPromise()
    .then((res:any) => this.extractData(res) as SaveResult[]);
  }

  genKey(userid: any) {
    return this.http.post(`${this.brandingAndPortalUrl}/admin/users/genKey`, {userid: userid}, this.options)
    .toPromise()
    .then((res:any) => this.extractData(res) as SaveResult[]);
  }

  revokeKey(userid: any) {
    return this.http.post(`${this.brandingAndPortalUrl}/admin/users/revokeKey`, {userid: userid}, this.options)
    .toPromise()
    .then((res:any) => this.extractData(res) as SaveResult[]);
  }

  updateUserProfile(details: any) {
    return this.http.post(`${this.brandingAndPortalUrl}/user/update`, {details:details}, this.options)
    .toPromise()
    .then((res:any) => this.extractData(res) as SaveResult[]);
  }

  genUserKey() {
    return this.http.post(`${this.brandingAndPortalUrl}/user/genKey`, {},this.options)
    .toPromise()
    .then((res:any) => this.extractData(res) as SaveResult[]);
  }

  revokeUserKey() {
    return this.http.post(`${this.brandingAndPortalUrl}/user/revokeKey`, {},this.options)
    .toPromise()
    .then((res:any) => this.extractData(res) as SaveResult[]);
  }

}

results matching ""

    No results matching ""