Skip to content

Commit a5b067d

Browse files
committed
Implemented a Guest login means direct login without signIN
1 parent 0f6ee65 commit a5b067d

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

controllers/user_controller.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ module.exports.signIn = async function (req, res) {
5757
else if (user && user.password == password) {
5858
const token = generateAccessToken(user.id, user.email);
5959
res.cookie("jwt_token", token); // , { maxAge: 1000, httpOnly: true } = for set the cookie expire time
60-
res.status(200).send(`<script> window.location.href='/user_dashboard'; </script>`);
60+
// res.status(200).send(`<script> window.location.href='/user_dashboard'; </script>`);
61+
// res.redirect('/user_dashboard');
62+
res.status(200).json({ redirect: '/user_dashboard' });
6163

6264
}
6365
}).catch((err) => {
@@ -272,9 +274,11 @@ module.exports.sendMail = async (req, res) => {
272274
sender,
273275
To: receivers,
274276
subject: "Expense Tracker Reset Password",
277+
275278
// textContent: "Link Below", (no need of text content because html content overide on textcontent)
279+
276280
htmlContent: `<h3> Hii! We got the request from you for reset the password. Here is the link below >>> </h3>
277-
<a href="http://localhost:9000/resetPasswordPage/{{params.requestId}}"> Reset your Password from here </a>`,
281+
<a href="http://localhost:9000/resetPasswordPage/{{params.requestId}}"> Reset your Password from here </a>`,
278282
params: {
279283
requestId: requestId,
280284
},

public/css/sign_up-login.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ button {
5959
transition: transform 80ms ease-in;
6060
}
6161

62+
#loginBtn2 {
63+
margin-top: 8px;
64+
border-radius: 20px;
65+
border: 1px solid #293241;
66+
background-color: #293241;
67+
color: #ffffff;
68+
font-size: 12px;
69+
font-weight: bold;
70+
padding: 12px 45px;
71+
letter-spacing: 1px;
72+
text-transform: uppercase;
73+
transition: transform 80ms ease-in;
74+
}
75+
6276
button:active {
6377
transform: scale(0.95);
6478
}

public/js/sign_up-login.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const signUp = document.getElementById("signUp");
22
const signIn = document.getElementById("signIn");
3+
const loginAsGuest = document.getElementById("loginBtn2");
34
// const container = document.getElementById("container");
45
// const signUpBtn = document.getElementById("signUpBtn");
56
// const loginBtn = document.getElementById("loginBtn");
@@ -14,6 +15,25 @@ signIn.addEventListener("click", () => {
1415
container.classList.remove("right-panel-active");
1516
});
1617

18+
loginAsGuest.addEventListener("click", login);
19+
20+
function login() {
21+
const loginDetails = {
22+
email: "guest@gmail.com",
23+
password: "guest123",
24+
};
25+
26+
// axios.post("http://localhost:9000/signIn", loginDetails);
27+
28+
axios.post('http://localhost:9000/signIn', loginDetails).then(response => {
29+
if (response.data.redirect) {
30+
window.location.href = response.data.redirect;
31+
}
32+
}).catch(error => {
33+
console.error('Error:', error);
34+
});
35+
}
36+
1737
// function login() {
1838
// const loginDetails = {
1939
// loginEmail: loginEmail.value,

public/views/sign_up-login.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ <h1>Login</h1>
3131
<input type="password" placeholder="Password" name="password" id="loginPassword" required />
3232
<a href="/forgotPasswordPage">Forgot Password?</a>
3333
<button type="submit" id="loginBtn">Login</button>
34+
<input type="button" id="loginBtn2" value="Login as guest" />
3435
</form>
3536
</div>
3637

@@ -55,6 +56,8 @@ <h1>Hello, Friend!</h1>
5556

5657
</div>
5758

59+
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.2.2/axios.min.js"></script>
60+
5861
<script src="js/sign_up-login.js"></script>
5962
</body>
6063

0 commit comments

Comments
 (0)