File

projects/congarevenuecloud/ecommerce/src/lib/modules/crm/services/user.service.ts

Description

The User service provides methods for getting current user related details.

Usage

Example :
import { UserService, AObjectService } from '@congarevenuecloud/ecommerce';

constructor(private userService: UserService) {}

// or

export class MyService extends AObjectService {
private userService: UserService = this.injector.get(UserService);
}

Extends

AObjectService

Index

Properties
Methods

Methods

getBrowserLocale
getBrowserLocale(underscore: boolean)

Retrieves the browser locale for the current user

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
lang:string;
constructor(private userService: UserService){}

getBrowserLocale(){
this.lang = this.userService.getBrowserLocale();
}
}
Parameters :
Name Type Optional Default value Description
underscore boolean No true

when set to true, will replace dash ('-') with an underscore ('_')

Returns : any
getCurrentUser
getCurrentUser()

Method gets active user.

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
user: User;
user$: Observable<User>
constructor(private userService: UserService){}

this.userService.getCurrentUser().subscribe(user => this.user = user);
// or
this.user$ = this.userService.getCurrentUser();

}
Returns : Observable<User>

observable instance of the active user.

getCurrentUserLocale
getCurrentUserLocale(underscore: boolean)

Retrieves the current user locale to support salesforce and other environment

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
lang:string;
constructor(private userService: UserService){}

getCurrentUserLanguage(){
this.lang = this.userService.getCurrentUserLocale();
}

}
Parameters :
Name Type Optional Default value Description
underscore boolean No true

when set to true, will replace dash ('-') with an underscore ('_')

Returns : Observable<string>

return an observable string for current user locale.

initializeGuestUser
initializeGuestUser()

Method is used to create a guest user record prior to registration. Will set the defaults on the record to browser defaults.

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
guestUser: User;
guestUser$: Observable<User>
constructor(private userService: UserService){}

this.userService.initializeGuestUser().subscribe(user => this.user = user);
// or
this.user$ = this.userService.initializeGuestUser();

}
Returns : Observable<User>

a user record containing the browser defaults (will not be committed to db).

isGuest
isGuest()

Used for determining if the current user is a guest user.

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
isGuest: boolean;
constructor(private userService: UserService){}

this.isGuest = this.userService.isGuest();

}
Returns : Observable<boolean>

a boolean observable. Will be true if the user is a guest user.

isLoggedIn
isLoggedIn()

Method is used to determine if the user has authenticated and successfully logged in.

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
isUserLoggedIn:boolean;
isUserLoggedIn$:Observable<boolean>;
constructor(private userService: UserService){}

checkLoginState():boolean {
this.userService.isLoggedIn().subscribe(res=> isUserLoggedIn = res);
// or
isUserLoggedIn$ = this.userService.isLoggedIn();
}
}
Returns : Observable<boolean>

a boolean observable. Returns true if the user is successfully logged in.

login
login()

Primary method responsible to log a user in to Conga platform

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}
login(){
this.userService.login();
}
}
Returns : void
logout
logout()

Primary method responsible to log a user out of Conga platform

Returns : void
me
me()

Primary method for retrieving the current user record.

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
user: User;
user$: Observable<User>
constructor(private userService: UserService){}

this.userService.me().subscribe(user => this.user = user);
// or
this.user$ = this.userService.me();

}
Returns : Observable<User>

an observable of type User.

onInit
onInit()
Returns : void
setCurrency
setCurrency(currencyIsoCode: string, commit: boolean)

Method sets the currency for the current user.

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
user: User;
user$: Observable<User>
constructor(private userService: UserService){}

this.userService.setCurrency(value).subscribe(user => this.user = user);
// or
this.user$ = this.userService.setCurrency(value);

}
Parameters :
Name Type Optional Default value Description
currencyIsoCode string No

the iso code of the currency to set (i.e. 'USD')

commit boolean No false

set to true to commit the change to the db.

Returns : Observable<User>

observable instance of current user with updated currency.

setLocale
setLocale(locale: string)

Method sets the locale for the current user.

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}

setLocale(value:string){
this.userService.setLocale(value);
}
}
Parameters :
Name Type Optional Description
locale string No

locale to set on current user

Returns : Observable<void>

an empty observable.

setUserDefaults
setUserDefaults(user: User)

Method sets the defaults like language, locale & email encoding type for user

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}

setDefaultUserData(value) {
this.userService.setUserDefaults(value);
}
}
Parameters :
Name Type Optional Description
user User No

the user record to set the defaults on

Returns : void
updateCurrentUser
updateCurrentUser(user: User)

Method updates the user details.

Example:

Example :
import { UserService, User } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private userService: UserService){}

updateUserInfo(value) {
this.userService.updateCurrentUser(value);
}
}
Parameters :
Name Type Optional Description
user User No

the user record to update.

Returns : Observable<User>

an observable of the updated user.

Properties

apiService
Type : ApiService
Default value : this.injector.get(ApiService)
Protected CACHE_KEY
Type : string
Default value : 'User'
securityService
Type : OidcSecurityService
Default value : this.injector.get(OidcSecurityService)
type
Default value : User

results matching ""

    No results matching ""