mirror of https://github.com/abpframework/abp.git
committed by
GitHub
7 changed files with 85 additions and 32 deletions
@ -0,0 +1,6 @@ |
|||
export interface LoginParams { |
|||
username: string; |
|||
password: string; |
|||
rememberMe?: boolean; |
|||
redirectUrl?: string; |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
import { Injector } from '@angular/core'; |
|||
import { Router } from '@angular/router'; |
|||
import { pipe } from 'rxjs'; |
|||
import { switchMap, tap } from 'rxjs/operators'; |
|||
import { LoginParams } from '../models/auth'; |
|||
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; |
|||
import { ConfigStateService } from '../services/config-state.service'; |
|||
|
|||
const cookieKey = 'rememberMe'; |
|||
const storageKey = 'passwordFlow'; |
|||
|
|||
export function pipeToLogin( |
|||
params: Pick<LoginParams, 'redirectUrl' | 'rememberMe'>, |
|||
injector: Injector, |
|||
) { |
|||
const configState = injector.get(ConfigStateService); |
|||
const appConfigService = injector.get(AbpApplicationConfigurationService); |
|||
const router = injector.get(Router); |
|||
|
|||
return pipe( |
|||
switchMap(() => appConfigService.get()), |
|||
tap(res => { |
|||
configState.setState(res); |
|||
setRememberMe(params.rememberMe); |
|||
if (params.redirectUrl) router.navigate([params.redirectUrl]); |
|||
}), |
|||
); |
|||
} |
|||
|
|||
export function setRememberMe(remember: boolean) { |
|||
removeRememberMe(); |
|||
localStorage.setItem(storageKey, 'true'); |
|||
document.cookie = `${cookieKey}=true; path=/${ |
|||
remember ? ' ;expires=Fri, 31 Dec 9999 23:59:59 GMT' : '' |
|||
}`;
|
|||
} |
|||
|
|||
export function removeRememberMe() { |
|||
localStorage.removeItem(storageKey); |
|||
document.cookie = cookieKey + '= ; path=/; expires = Thu, 01 Jan 1970 00:00:00 GMT'; |
|||
} |
|||
@ -1,4 +1,24 @@ |
|||
import { HttpParameterCodec } from '@angular/common/http'; |
|||
|
|||
export function getPathName(url: string): string { |
|||
const { pathname } = new URL(url, window.location.origin); |
|||
return pathname; |
|||
} |
|||
|
|||
export class WebHttpUrlEncodingCodec implements HttpParameterCodec { |
|||
encodeKey(k: string): string { |
|||
return encodeURIComponent(k); |
|||
} |
|||
|
|||
encodeValue(v: string): string { |
|||
return encodeURIComponent(v); |
|||
} |
|||
|
|||
decodeKey(k: string): string { |
|||
return decodeURIComponent(k); |
|||
} |
|||
|
|||
decodeValue(v: string) { |
|||
return decodeURIComponent(v); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue