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 @@

Liên hệ tòa soạn

-
- Họ và Tên - -
-
- Email - -
-
- Tiêu đề - -
-
- Chọn file - -
+
+
+ Họ và Tên + +
+
+ Email + +
+
+ Tiêu đề + +
-
- Nội dung - -
+ +
+ Nội dung + +
+
+ +
+
- \ No newline at end of file + diff --git a/src/app/pages/contact/contact.component.scss b/src/app/pages/contact/contact.component.scss index c0c5608..9d2f0c2 100644 --- a/src/app/pages/contact/contact.component.scss +++ b/src/app/pages/contact/contact.component.scss @@ -26,5 +26,10 @@ height: 150px; } } + .submit-panel{ + display: flex; + flex-direction: row-reverse; + margin-top: 10px; + } } } diff --git a/src/app/pages/contact/contact.component.ts b/src/app/pages/contact/contact.component.ts index e492c7d..928b7d2 100644 --- a/src/app/pages/contact/contact.component.ts +++ b/src/app/pages/contact/contact.component.ts @@ -1,4 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {FormBuilder, FormControl, Validators} from "@angular/forms"; +import {HttpClient} from "@angular/common/http"; +import {Router} from "@angular/router"; +import {API_AUTH, API_URL} from "../../_api/apiURL"; +import {CommonService} from "../../_service/common.service"; @Component({ selector: 'app-contact', @@ -6,10 +11,31 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./contact.component.scss'] }) export class ContactComponent implements OnInit { + contactForm: any; - constructor() { } + constructor(private formBuilder: FormBuilder, private http: HttpClient,private commonService: CommonService, private router: Router) { + } ngOnInit(): void { + this.contactForm = this.formBuilder.group({ + email: new FormControl("", [Validators.required, Validators.email]), + name: new FormControl("", [Validators.required]), + title: new FormControl("", [Validators.required]), + text: new FormControl("", [Validators.required]) + }) } + contact() { + this.http.post(API_URL.CONTACT, { + "email": this.contactForm.value.email, + "name": this.contactForm.value.name, + "title": this.contactForm.value.title, + "text": this.contactForm.value.text + }).subscribe(res => { + this.commonService.toastSuccess("Gửi tin thành công thành công!") + window.location.reload(); + },error => { + this.commonService.toastError("Gửi tin thất bại!!") + }); + } } diff --git a/src/app/post/post-details/post-details.component.css b/src/app/post/post-details/post-details.component.css index f10982e..f9062c3 100644 --- a/src/app/post/post-details/post-details.component.css +++ b/src/app/post/post-details/post-details.component.css @@ -37,4 +37,13 @@ text-decoration: underline; } +.btn__save--post { + font-weight: 500; + transition: all 0.2s ease-in-out; +} +.btn__save--post:hover { + background-color: #f93154; + color: white; +} + /*# sourceMappingURL=post-details.component.css.map */ diff --git a/src/app/post/post-details/post-details.component.css.map b/src/app/post/post-details/post-details.component.css.map index e0b2243..de5a6af 100644 --- a/src/app/post/post-details/post-details.component.css.map +++ b/src/app/post/post-details/post-details.component.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["post-details.component.scss"],"names":[],"mappings":"AAAA;EACE;;;AAGF;EACE;;;AAGF;EACE;IACE;;EAEF;IACE;;;AAIJ;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAEF;EACE;;AACA;EACE;EACA;;AAEF;EACE","file":"post-details.component.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["post-details.component.scss"],"names":[],"mappings":"AAAA;EACE;;;AAGF;EACE;;;AAGF;EACE;IACE;;EAEF;IACE;;;AAIJ;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAEF;EACE;;AACA;EACE;EACA;;AAEF;EACE;;;AAIJ;EACE;EACA;;AACA;EACE;EACA","file":"post-details.component.css"} \ No newline at end of file diff --git a/src/app/profile/read-posts/read-posts.component.css b/src/app/profile/read-posts/read-posts.component.css new file mode 100644 index 0000000..80c6739 --- /dev/null +++ b/src/app/profile/read-posts/read-posts.component.css @@ -0,0 +1,54 @@ +.container { + display: flex; + justify-content: center; +} +.container .left-panel { + display: flex; + width: 20%; + justify-content: flex-start; + flex-direction: column; + align-items: center; +} +.container .left-panel .img-group { + display: flex; + align-items: baseline; +} +.container .left-panel .img-group .fa-camera { + position: relative; + right: 30px; +} +.container .left-panel .img-group .profile-img { + width: 150px; + height: 150px; + border-radius: 50%; + margin-bottom: 20px; +} +.container .left-panel .link-group { + margin-top: 80px; +} +.container .left-panel .link-group .red { + color: red; +} +.container .right-panel { + border: 1px solid black; + padding: 30px 20px 60px; +} +.container .right-panel .title { + color: #467fd7; +} + +.news-title { + color: black; + text-decoration: none; + font-weight: bold; +} +.news-title:hover { + text-decoration: underline; + color: black; +} + +.delete__action { + cursor: pointer; +} + +/*# sourceMappingURL=read-posts.component.css.map */ diff --git a/src/app/profile/read-posts/read-posts.component.css.map b/src/app/profile/read-posts/read-posts.component.css.map new file mode 100644 index 0000000..3085d2a --- /dev/null +++ b/src/app/profile/read-posts/read-posts.component.css.map @@ -0,0 +1 @@ +{"version":3,"sourceRoot":"","sources":["read-posts.component.scss"],"names":[],"mappings":"AAAA;EACE;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;;AACA;EACE;EACA;;AAEF;EACE;EACA;EACA;EACA;;AAIJ;EACE;;AAEA;EACE;;AAKN;EACE;EACA;;AACA;EACE;;;AAIN;EACE;EACA;EACA;;AACA;EACE;EACA;;;AAGJ;EACE","file":"read-posts.component.css"} \ No newline at end of file