diff --git a/db.json b/db.json index 56b2ec1..3e0e318 100644 --- a/db.json +++ b/db.json @@ -203,5 +203,14 @@ ], "id": 2 } + ], + "contact": [ + { + "email": "hoang@gmail.com", + "name": "hoang", + "title": "hoang", + "text": "abcaaaaa", + "id": 1 + } ] } \ No newline at end of file diff --git a/src/app/_api/apiURL.ts b/src/app/_api/apiURL.ts index 15e9daf..4214d3b 100644 --- a/src/app/_api/apiURL.ts +++ b/src/app/_api/apiURL.ts @@ -29,5 +29,6 @@ export const API_URL = { GET_LIST: "https://api-news-vietnamnet.herokuapp.com/api/get/", SEARCH: "https://api-news-vietnamnet.herokuapp.com/api/search/", ARTICLE_DETAILS: "https://api-news-vietnamnet.herokuapp.com/article/", - ARTICLE_SAVED: "http://localhost:3000/saved-post" + ARTICLE_SAVED: "http://localhost:3000/saved-post", + CONTACT:"http://localhost:3000/contact" } diff --git a/src/app/_service/auth.service.ts b/src/app/_service/auth.service.ts index f876983..a218219 100644 --- a/src/app/_service/auth.service.ts +++ b/src/app/_service/auth.service.ts @@ -30,8 +30,15 @@ export class AuthService { if (user) { if (user.comfirmToken === "ok") { this.tokenStorage.saveUser(user); - console.log(user); localStorage.setItem("isSignin", "true"); + if (siginForm.value.rememberCheck == true) { + this.tokenStorage.rememberAccount({ + "email": user.email, + "password": user.password, + }) + }else{ + this.tokenStorage.deleteRememberInfo() + } siginForm.reset(); this.router.navigate(['home']) } else { diff --git a/src/app/_service/token-storage.service.ts b/src/app/_service/token-storage.service.ts index ec8ca74..d57ea99 100644 --- a/src/app/_service/token-storage.service.ts +++ b/src/app/_service/token-storage.service.ts @@ -1,7 +1,7 @@ -import { Injectable } from '@angular/core'; -import { Router } from '@angular/router'; +import {Injectable} from '@angular/core'; +import {Router} from '@angular/router'; -const TOKEN_KEY = 'auth-token'; +const REMEMBER_KEY = 'remember-token'; const USER_KEY = 'auth-user' @Injectable({ @@ -13,7 +13,9 @@ export class TokenStorageService { } signOut(): void { - localStorage.clear(); + + localStorage.removeItem(USER_KEY); + localStorage.removeItem("isSignin"); this.router.navigate(['/signin']); } @@ -31,6 +33,22 @@ export class TokenStorageService { localStorage.setItem(USER_KEY, JSON.stringify(user)); } + public rememberAccount(account: any): void { + localStorage.setItem(REMEMBER_KEY, JSON.stringify(account)); + } + + public getRememberAccount(): any { + const account = localStorage.getItem(REMEMBER_KEY); + if (account) { + return JSON.parse(account) + } + return {} + } + + public deleteRememberInfo(): void { + localStorage.removeItem(REMEMBER_KEY); + } + public getUser(): any { const user = localStorage.getItem(USER_KEY); if (user) { @@ -38,7 +56,8 @@ export class TokenStorageService { } return {} } - public isSignin():any{ - return localStorage.getItem("isSignin") == "true" + + public isSignin(): any { + return localStorage.getItem("isSignin") == "true" } } diff --git a/src/app/auth/register/register-form/register-form.component.ts b/src/app/auth/register/register-form/register-form.component.ts index cc0efa5..2217e38 100644 --- a/src/app/auth/register/register-form/register-form.component.ts +++ b/src/app/auth/register/register-form/register-form.component.ts @@ -6,6 +6,7 @@ import { } from "@angular/forms"; import {Router} from "@angular/router"; import {AuthService} from "../../../_service/auth.service"; +import {CommonService} from "../../../_service/common.service"; export function comparePassword(c: AbstractControl) { const v = c.value; @@ -24,7 +25,7 @@ export class RegisterFormComponent implements OnInit { public registerForm !: FormGroup; submitted = false; - constructor(private formBuilder: FormBuilder, private http: HttpClient, private router: Router, private authService: AuthService) { + constructor(private formBuilder: FormBuilder, private http: HttpClient,private commonService: CommonService, private router: Router, private authService: AuthService) { } ngOnInit(): void { @@ -53,11 +54,11 @@ export class RegisterFormComponent implements OnInit { alert("email đã đăng kí tài khoản. xin sử dụng email khác !") } else if (!this.registerForm.hasError('passwordnotmatch', ['pw']) && this.registerForm.value['termCheck'] == true) { this.authService.register(this.registerForm.value['email'], this.registerForm.controls['pw'].value.password).subscribe(res => { - alert("register success"); + this.commonService.toastSuccess("Đăng kí thành công thành công!") this.router.navigate(['signin']); }, error => { - alert("register false ") + this.commonService.toastError("Đăng kí thất bại!! Xin vui lòng thử lại") }) } }) diff --git a/src/app/auth/signin/signin-form/signin-form.component.ts b/src/app/auth/signin/signin-form/signin-form.component.ts index 002c451..65e42db 100644 --- a/src/app/auth/signin/signin-form/signin-form.component.ts +++ b/src/app/auth/signin/signin-form/signin-form.component.ts @@ -13,16 +13,18 @@ import {API_AUTH} from 'src/app/_api/apiURL'; }) export class SigninFormComponent implements OnInit { public siginForm !: FormGroup; - + rememberAccount: any; constructor(private formBuilder: FormBuilder, private http: HttpClient, private router: Router, private authService: AuthService, private tokenStorage: TokenStorageService) { } ngOnInit(): void { + this.rememberAccount = this.tokenStorage.getRememberAccount() + this.siginForm = this.formBuilder.group({ - email: new FormControl("", [Validators.required, Validators.email]), - password: new FormControl("", [Validators.required]), - rememberCheck: new FormControl("") + email: new FormControl(this.rememberAccount.email, [Validators.required, Validators.email]), + password: new FormControl(this.rememberAccount.password, [Validators.required]), + rememberCheck: new FormControl(this.rememberAccount!={}) }) } diff --git a/src/app/pages/contact/contact.component.css b/src/app/pages/contact/contact.component.css index 2967b86..9ba19e1 100644 --- a/src/app/pages/contact/contact.component.css +++ b/src/app/pages/contact/contact.component.css @@ -22,5 +22,10 @@ .container .contact-panel .input-group .context { height: 150px; } +.container .contact-panel .submit-panel { + display: flex; + flex-direction: row-reverse; + margin-top: 10px; +} /*# sourceMappingURL=contact.component.css.map */ diff --git a/src/app/pages/contact/contact.component.css.map b/src/app/pages/contact/contact.component.css.map index b1d9949..7bdee3c 100644 --- a/src/app/pages/contact/contact.component.css.map +++ b/src/app/pages/contact/contact.component.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["contact.component.scss"],"names":[],"mappings":"AAAA;EACE;EACA;;AAEA;EACE;EACA;;AAEA;EACE;EACA;;AAGF;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE","file":"contact.component.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["contact.component.scss"],"names":[],"mappings":"AAAA;EACE;EACA;;AAEA;EACE;EACA;;AAEA;EACE;EACA;;AAGF;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGJ;EACE;EACA;EACA","file":"contact.component.css"} \ No newline at end of file diff --git a/src/app/pages/contact/contact.component.html b/src/app/pages/contact/contact.component.html index 2599b0b..b7ead48 100644 --- a/src/app/pages/contact/contact.component.html +++ b/src/app/pages/contact/contact.component.html @@ -4,30 +4,35 @@