Get working enough for other app access
Docker Build and Release Upload / build (push) Successful in 1m24s
Docker Build and Release Upload / build (push) Successful in 1m24s
This commit is contained in:
@@ -15,7 +15,9 @@ export class App {
|
||||
@ViewChild('jobsLink') jobLink!: ElementRef<HTMLAnchorElement>;
|
||||
@ViewChild('resumesLink') resumeLink!: ElementRef<HTMLAnchorElement>;
|
||||
|
||||
constructor(public auth: Authentication, private router: Router){}
|
||||
constructor(public auth: Authentication, private router: Router){
|
||||
this.auth.getLoginState();
|
||||
}
|
||||
|
||||
ngAfterViewInit(){
|
||||
let ViewLinks = [ this.homeLink, this.resumeLink, this.jobLink ];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export class Account {
|
||||
public id: number = 0;
|
||||
public id: number = -1;
|
||||
public userName: string = "";
|
||||
public email: string = "";
|
||||
public emailVerified: boolean = false;
|
||||
|
||||
@@ -43,7 +43,7 @@ export class LoginComponent {
|
||||
}
|
||||
|
||||
this.errorMsgs.push("Waiting for response from server");
|
||||
this.http.post( "https://auth.mistox.com/api/auth/login", { "UserName": this.UserName, "Password": this.Password, "StayLoggedIn": this.StayLoggedIn }, { responseType: 'text' } ).subscribe({
|
||||
this.http.post( "api/auth/login", { "UserName": this.UserName, "Password": this.Password, "StayLoggedIn": this.StayLoggedIn }, { responseType: 'text' } ).subscribe({
|
||||
next: data => {
|
||||
this.errorMsgs = [ "Login Token: " + data ];
|
||||
window.location.href = this.returnURL + "?LoginToken=" + data;
|
||||
|
||||
@@ -6,30 +6,21 @@ import { HttpClient, HttpHeaders, HttpParams } from "@angular/common/http";
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class Authentication{
|
||||
|
||||
private _user = new BehaviorSubject<Account>(this.getUserFromStorage());
|
||||
private _user = new BehaviorSubject<Account>( new Account );
|
||||
user$ = this._user.asObservable();
|
||||
|
||||
constructor( private http: HttpClient){ }
|
||||
|
||||
Login(UserName: string, Password: string, StayLoggedIn: boolean): Observable<Account> {
|
||||
|
||||
const body = new HttpParams()
|
||||
.set("UserName", UserName)
|
||||
.set("PasswordHash", Password)
|
||||
.set("StayLoggedIn", StayLoggedIn );
|
||||
const headers = new HttpHeaders({
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
});
|
||||
|
||||
let sub = this.http.post<Account>( "api/account/login", body, { headers } );
|
||||
getLoginState(): Observable<Account> {
|
||||
const headers = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' });
|
||||
let sub = this.http.post<Account>( "api/loginState", {}, { headers } );
|
||||
sub.subscribe({
|
||||
next: data => {
|
||||
data.passwordHash = "";
|
||||
this._user.next(data);
|
||||
this.setUserToStorage(data, StayLoggedIn == true ? SessionType.Forever : SessionType.Session);
|
||||
},
|
||||
error: err => {
|
||||
console.log("HTTP Error Signing In: ", err.error);
|
||||
console.log("No login state found: ", err.error);
|
||||
}
|
||||
});
|
||||
return sub;
|
||||
@@ -37,8 +28,7 @@ export class Authentication{
|
||||
|
||||
Logout(){
|
||||
this._user.next( new Account );
|
||||
this.delUserFromStorage();
|
||||
return this.http.post<Account>( "api/account/logout", {}, { responseType: 'json' } );
|
||||
return this.http.post<Account>( "api/logout", {}, { responseType: 'json' } );
|
||||
}
|
||||
|
||||
get isLoggedIn(): boolean {
|
||||
@@ -48,33 +38,6 @@ export class Authentication{
|
||||
get loggedInUser(): Account {
|
||||
return this._user.value;
|
||||
}
|
||||
|
||||
private getUserFromStorage(): Account {
|
||||
const foreverUser = localStorage.getItem('user');
|
||||
const sessionUser = sessionStorage.getItem('user');
|
||||
let user = null;
|
||||
if (foreverUser != null){
|
||||
user = JSON.parse(foreverUser)
|
||||
} else if (sessionUser != null){
|
||||
user = JSON.parse(sessionUser)
|
||||
} else {
|
||||
user = new Account();
|
||||
user.id = -1;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
private setUserToStorage(user: Account, session: SessionType): void {
|
||||
if (session == SessionType.Forever){
|
||||
localStorage.setItem('user', JSON.stringify(user));
|
||||
}else if(session == SessionType.Session){
|
||||
sessionStorage.setItem('user', JSON.stringify(user));
|
||||
}
|
||||
}
|
||||
private delUserFromStorage(): void {
|
||||
localStorage.removeItem('user');
|
||||
sessionStorage.removeItem('user');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export enum SessionType {
|
||||
|
||||
@@ -4,9 +4,6 @@ using Auth.Services.DatabaseService;
|
||||
using Auth.Entities;
|
||||
using Auth.DTO;
|
||||
using System.Web.Http;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Auth.Controllers {
|
||||
[ApiController]
|
||||
@@ -19,9 +16,9 @@ namespace Auth.Controllers {
|
||||
_emailContext = emailContext;
|
||||
}
|
||||
|
||||
[Route("get")]
|
||||
[Route("loginState")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Account>> Get() {
|
||||
public async Task<ActionResult<Account>> LoginState() {
|
||||
try {
|
||||
if (isLoggedIn()) {
|
||||
return Ok(await getLoggedInUser());
|
||||
@@ -33,47 +30,6 @@ namespace Auth.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
[Route("login")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Account>> Login([FromBody] LoginRequest request) {
|
||||
try {
|
||||
Account? test = await _databaseService.GetAccount(request.UserName.ToLower());
|
||||
if (test != null) {
|
||||
if (test.EmailVerified == true) {
|
||||
if (test.FailedPasswordLock) {
|
||||
if (test.CurrentPasswordAttempts >= test.PasswordAttempts) {
|
||||
return BadRequest("Too many failed password attempts. Please reset your password");
|
||||
}
|
||||
}
|
||||
if (BCrypt.Net.BCrypt.Verify(request.Password, test.PasswordHash)) {
|
||||
test.CurrentPasswordAttempts = 0;
|
||||
await _databaseService.SetAccount(test);
|
||||
|
||||
string jwt = AuthJWT.GenereateJWTToken(test, request.StayLoggedIn);
|
||||
SignIn(Response, jwt);
|
||||
|
||||
return Ok(test);
|
||||
}
|
||||
else {
|
||||
test.CurrentPasswordAttempts += 1;
|
||||
await _databaseService.SetAccount(test);
|
||||
return BadRequest("Wrong Password");
|
||||
}
|
||||
}
|
||||
else {
|
||||
await SendVerify(new SendVerifyEmailRequest {
|
||||
UserName = test.UserName
|
||||
});
|
||||
return BadRequest("A new verify email has been sent. \n Note only 1 email send every 5 mintes");
|
||||
}
|
||||
}
|
||||
return BadRequest("Account Not Found");
|
||||
} catch (Exception ex) {
|
||||
Console.WriteLine("Login Error: " + ex.Message);
|
||||
return BadRequest("An internal server error has occured");
|
||||
}
|
||||
}
|
||||
|
||||
[Route("logout")]
|
||||
[HttpPost]
|
||||
public ActionResult Logout() {
|
||||
|
||||
Reference in New Issue
Block a user