Skip to content

Commit

Permalink
[ Gb-77 ] Add register page and login with email and password (#5)
Browse files Browse the repository at this point in the history
* Add the base login and register page

* add style to input block

* Add method to handler login and register

* add package sha1 to check compromised password

* Fix wrong from label

* Fix bug if compromised password the account still created

* fix: Correct the function call syntax

* fix: Check the password and confirm password match

* fix: Update the wording for username to be name-surname

---------

Co-authored-by: Siratee K <sirateek@gmail.com>
  • Loading branch information
TaninDean and sirateek authored May 14, 2023
1 parent 63fc3ae commit 6b17353
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@types/sha1": "^1.1.3",
"axios": "^0.23.0",
"core-js": "^3.6.5",
"dotenv": "^10.0.0",
"firebase": "^8.6.2",
"firebaseui": "^4.8.0",
"sha1": "^1.1.1",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3",
"vue-material": "^1.0.0-beta-15",
Expand Down
6 changes: 6 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TagDetailView from "@/views/Tag/TagDetailView.vue";
import Account from "@/views/Account/Account.vue";
import LinkAccount from "@/views/Account/LinkAccount.vue";
import PageNotFound from "@/views/PageNotFound.vue";
import Register from "@/views/Register.vue"

Vue.use(VueRouter);

Expand All @@ -24,6 +25,11 @@ const routes: Array<RouteConfig> = [
name: "SignIn",
component: SignIn,
},
{
path: "/register",
name: "Register",
component: Register,
},
{
path: "/home",
name: "HomePage",
Expand Down
1 change: 1 addition & 0 deletions src/sha1.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'sha1';
123 changes: 123 additions & 0 deletions src/views/Register.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<template>
<div class="registerBox">
<md-card class="registerCard">
<md-card-media-actions>
<md-card-media>
<img src="@/assets/images/garnbarn-logo.png" class="garnbarnLogo" />
</md-card-media>

<md-card-actions>
<h3>Register to GarnBarn</h3>
<div>
<form @submit.prevent="register">
<div class="user">
<label for="username">Name - Surname:</label>
<input id="username" v-model="username" type="text" />
</div>
<div class="user">
<label for="username">Email:</label>
<input id="username" v-model="email" type="text" />
</div>
<div class="pass">
<label for="password">Password:</label>
<input id="password" v-model="password" type="password" />
</div>
<div class="con-pass">
<label for="confirmPassword">Confirm Password:</label>
<input id="confirmPassword" v-model="confirmPassword" type="password" />
</div>
<div>
<button type="submit">Register</button>
</div>
</form>
</div>
</md-card-actions>
</md-card-media-actions>
</md-card>
</div>
</template>

<script lang="ts">
import firebase from "firebase";
import { Vue, Component } from 'vue-property-decorator';
import sha1 from 'sha1';
@Component
export default class Register extends Vue {
username = '';
password = '';
confirmPassword = '';
email = ''
checkCompromisedPassword(): boolean {
const hashedPassword: string = sha1(this.password);
// todo send api
return true
}
register(): void {
if (!this.checkCompromisedPassword()) {
alert('Your passoword is compromised')
return
}
if (this.password !== this.confirmPassword) {
alert('Password and Confirm Password missmatched')
return
}
firebase
.auth()
.createUserWithEmailAndPassword(this.email, this.password)
.then((res) => {
res.user!
.updateProfile({
displayName: this.username
})
.then(() => {
this.$router.push('/signin')
});
})
.catch((error) => {
alert(error.message);
});
}
}
</script>

<style scoped>
.registerBox {
padding-top: 5%;
padding-top: 5%;
}
.registerCard {
padding: 10px;
padding-top: 15px;
border-radius: 20px;
background-color: #f9f9f9;
display: inline-block;
vertical-align: top;
overflow: auto;
border: 1px solid rgba(#000, 0.12);
}
.garnbarnLogo {
width: 150px;
height: auto;
}
hr.rounded {
margin-top: 5%;
margin-bottom: 5%;
margin-left: 10%;
margin-right: 10%;
border-top: 2px solid #bbb;
border-radius: 5px;
}
.ruser,
.pass,
.con-pass {
margin: 0.25rem;
}
</style>
60 changes: 60 additions & 0 deletions src/views/SignIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@

<md-card-actions>
<h3>Sign in to GarnBarn</h3>
<div>
<form @submit.prevent="login">
<div class="auth">
<div>
<label for="username">Email:</label>
<input id="username" v-model="email" type="text" />
</div>
<div class="password">
<label for="password">Password:</label>
<input id="password" v-model="password" type="password" />
</div>
</div>
<div class="register-link">
<div>Don't have an account?<router-link to="/register">Register</router-link></div>
</div>
<div class="forget-password">
<router-link to="/forgot">Forgot your password?</router-link>
</div>
<div>
<button type="submit">Login</button>
</div>
</form>
</div>
<div class="or">
<p>or</p>
</div>
<section id="firebaseui-auth-container"></section>
</md-card-actions>
</md-card-media-actions>
Expand All @@ -23,6 +49,9 @@ import { Component, Vue } from "vue-property-decorator";
@Component
export default class SignIn extends Vue {
email = '';
password = '';
mounted(): void {
let firebaseAuthInstance: firebase.auth.Auth = firebase.auth();
let uiConfig: any = {
Expand All @@ -33,6 +62,18 @@ export default class SignIn extends Vue {
let ui = new firebaseUi.auth.AuthUI(firebaseAuthInstance);
ui.start("#firebaseui-auth-container", uiConfig);
}
login(): void {
firebase
.auth()
.signInWithEmailAndPassword(this.email, this.password)
.then(() => {
this.$router.push('/home')
})
.catch((error) => {
alert(error.message);
});
}
}
</script>

Expand Down Expand Up @@ -66,4 +107,23 @@ hr.rounded {
border-top: 2px solid #bbb;
border-radius: 5px;
}
.forget-password {
text-align: right;
margin-bottom: 0.25rem;
}
.password {
margin: 0.25rem;
}
p {
margin-block-start: 1rem;
margin-block-end: 0em;
}
.or {
font-size: 1.5rem;
font-weight: 500;
}
</style>
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,13 @@
"@types/mime" "^1"
"@types/node" "*"

"@types/sha1@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@types/sha1/-/sha1-1.1.3.tgz#d4cc37f17d093c524382d90326ba7274ef4637a8"
integrity sha512-bXfx/6xrPu1l6pLItGRMPX00lhnJavpj2qiQeLHflXvL2Ix97aC8FTF2/pQoqukRzcCwKyN3csZvOLzamIoaSA==
dependencies:
"@types/node" "*"

"@types/sinonjs__fake-timers@^6.0.2":
version "6.0.4"
resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-6.0.4.tgz#0ecc1b9259b76598ef01942f547904ce61a6a77d"
Expand Down Expand Up @@ -4373,6 +4380,11 @@ chardet@^0.7.0:
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==

"charenc@>= 0.0.1":
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
integrity sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==

check-more-types@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/check-more-types/-/check-more-types-2.24.0.tgz#1420ffb10fd444dcfc79b43891bbfffd32a84600"
Expand Down Expand Up @@ -5016,6 +5028,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

"crypt@>= 0.0.1":
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
integrity sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==

crypto-browserify@^3.0.0, crypto-browserify@^3.11.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec"
Expand Down Expand Up @@ -12445,6 +12462,14 @@ sha.js@^2.4.0, sha.js@^2.4.8, sha.js@~2.4.4:
inherits "^2.0.1"
safe-buffer "^5.0.1"

sha1@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/sha1/-/sha1-1.1.1.tgz#addaa7a93168f393f19eb2b15091618e2700f848"
integrity sha512-dZBS6OrMjtgVkopB1Gmo4RQCDKiZsqcpAQpkV/aaj+FCrCg8r4I4qMkDPQjBgLIxlmu9k4nUbWq6ohXahOneYA==
dependencies:
charenc ">= 0.0.1"
crypt ">= 0.0.1"

shallow-clone@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/shallow-clone/-/shallow-clone-3.0.1.tgz#8f2981ad92531f55035b01fb230769a40e02efa3"
Expand Down

0 comments on commit 6b17353

Please sign in to comment.