Changeset 79a0317 for imaps-frontend/src/pages/Login
- Timestamp:
- 01/21/25 03:08:24 (4 days ago)
- Branches:
- main
- Parents:
- 0c6b92a
- Location:
- imaps-frontend/src/pages/Login
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/src/pages/Login/Login.jsx
r0c6b92a r79a0317 6 6 import HttpService from "../../scripts/net/HttpService.js"; 7 7 import {useAppContext} from "../../components/AppContext/AppContext.jsx"; 8 import config from "../../scripts/net/netconfig.js"; 8 import config, {API_BASE_URL} from "../../scripts/net/netconfig.js"; 9 import google_icon from "../../assets/Logo-google-icon-PNG.png" 10 import github_icon from "../../assets/github-mark-white.png"; 11 import { v4 as uuidv4 } from 'uuid'; 9 12 10 13 const LoginPage = () => { … … 26 29 const handleLogin = async () => { 27 30 const httpService = new HttpService(); 28 return httpService.post(config.auth.login, payload) 29 31 return httpService.post(config.auth.login, payload); 30 32 }; 31 32 33 33 34 const login = async (e) => { … … 37 38 .then(resp => { 38 39 if (resp.token) { 39 navigate(targetPath) 40 navigate(targetPath); 40 41 localStorage.setItem("token", resp.token); 41 42 setUsername(resp.username); 42 43 setIsAuthenticated(true); 43 console.log("ROLES", resp.roles)44 console.log("ROLES", resp.roles); 44 45 } else { 45 46 setError("Invalid username or password."); … … 47 48 }).catch(reason => { 48 49 console.error("Login failed", reason); 49 setError("Login failed. Please try again.") 50 }) 50 setError("Login failed. Please try again."); 51 }); 52 }; 51 53 52 // fetch("http://localhost:8080/api/auth/login", { 53 // method: "POST", 54 // headers: { 55 // "Content-Type": "application/json", 56 // }, 57 // body: JSON.stringify(payload), 58 // }) 59 // .then((response) => { 60 // if (!response.ok) { 61 // throw new Error("Login failed: resp = " + response.statusText); 62 // } 63 // return response.json(); 64 // }) 65 // .then((data) => { 66 // if (data.token) { 67 // navigate(targetPath); 68 // handleLogin(data); 69 // } else { 70 // setError("Invalid username or password."); 71 // } 72 // }) 73 // .catch((error) => { 74 // console.error("Login failed", error); 75 // setError("Login failed. Please try again."); 76 // }); 54 const continueWithGitHub = async () => { 55 const httpService = new HttpService(); 56 httpService.setResponseType('text'); 57 const state = await httpService.get(config.auth.oauth.github.state) 58 const clientId = 'Iv23liqzhX5wMYNDHtnz'; 59 const redirectUri = encodeURI(`${API_BASE_URL}/oauth/callback/github`); 60 61 const githubAuthUrl = `https://github.com/login/oauth/authorize?client_id=${encodeURI(clientId)}&redirect_uri=${redirectUri}&state=${encodeURI(state)}&scope=user:email`; 62 63 window.location.href = githubAuthUrl; 64 65 }; 66 67 const continueWithGoogle = async () => { 68 console.log("Continue with Google"); 69 const httpService = new HttpService(); 70 httpService.setResponseType('text'); 71 const state = await httpService.get(config.auth.oauth.github.state) 72 const clientId = '1024418489231-ml40ukvqcg9ad1h5ejor5dm6ipt6p8fo.apps.googleusercontent.com'; 73 const redirectUri = encodeURI(`${API_BASE_URL}/oauth/callback/google`); 74 const googleAuthUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${encodeURIComponent(clientId)} 75 &redirect_uri=${encodeURIComponent(redirectUri)}&state=${encodeURIComponent(state)}&response_type=code&scope=${encodeURIComponent("openid profile email")}`; 76 window.location.href = googleAuthUrl 77 77 }; 78 78 … … 111 111 <button type="submit">Submit</button> 112 112 </form> 113 <div className={styles.or}>OR</div> 114 <div className={styles.socialButtons}> 115 <button className={styles.socialButton} onClick={continueWithGoogle}> 116 <img src={google_icon} alt="Facebook Icon" className={styles.socialIcon}/> 117 Sign In With Google 118 </button> 119 <button className={styles.socialButton} onClick={continueWithGitHub}> 120 <img src={github_icon} alt="GitHub Icon" className={styles.socialIcon}/> 121 Sign In With GitHub 122 </button> 123 </div> 113 124 <p> 114 125 Don't have an account? <Link to="/Signup"> Sign Up </Link> -
imaps-frontend/src/pages/Login/Login.module.css
r0c6b92a r79a0317 13 13 14 14 .wrapper { 15 display: -webkit-box;16 display: -ms-flexbox;17 15 display: flex; 16 justify-content: flex-end; /* Move content towards the right */ 17 align-items: center; /* Center content vertically */ 18 18 height: 100vh; 19 -webkit-box-align: center; 20 -ms-flex-align: center; 21 align-items: center; 22 } 23 24 .wrapper p { 25 font-size: 0.85rem; 26 margin-top: 1rem; 27 } 19 margin-left: 30%; 20 padding: 2rem; 21 } 22 23 28 24 29 25 .form { 30 padding: 1.5rem; 31 -ms-flex-preferred-size: 100vw; 32 flex-basis: 100vw; 26 padding: 2rem; 27 display: flex; 28 flex-direction: column; /* Stack form elements vertically */ 29 align-items: center; /* Center form elements horizontally */ 30 justify-content: center; /* Vertically center the form */ 31 background-color: #fff; 32 border-radius: 8px; /* Rounded corners for the form */ 33 box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Add subtle shadow to form */ 34 width: 100%; 35 max-width: 400px; /* Restrict the form width for better appearance */ 33 36 } 34 37 35 38 .form .heading { 36 font-size: 1. 5rem;39 font-size: 1.8rem; 37 40 font-weight: bold; 38 41 text-align: center; 42 margin-bottom: 1.5rem; /* Spacing between heading and form */ 39 43 } 40 44 41 45 .or { 42 margin: 1rem 0; 46 margin-top: 1em; 47 text-align: center; 48 font-weight: bold; 49 color: #666; 43 50 } 44 51 … … 46 53 display: block; 47 54 margin: 1.25rem 0 1rem 0; 55 font-size: 0.95rem; 56 color: #333; 48 57 } 49 58 … … 51 60 height: 40px; 52 61 width: 100%; 62 max-width: 350px; /* Slightly larger max-width */ 53 63 padding: 15px; 54 64 background-color: #f1f9ff; 55 65 border: 2px solid #bce0fd; 56 66 border-radius: 8px; 67 box-sizing: border-box; 68 font-size: 1rem; /* Make input text a bit larger */ 57 69 } 58 70 … … 60 72 height: 40px; 61 73 width: 100%; 74 max-width: 350px; 75 margin-top: 1.5rem; 62 76 background-color: #258de6; 63 77 color: white; … … 65 79 letter-spacing: 1px; 66 80 border: none; 67 display: block; 68 margin: 0 auto; 69 font-weight: bold; 70 margin-top: 1.5rem; 81 font-weight: bold; 71 82 border-radius: 8px; 83 font-size: 1rem; /* Increase font size for better readability */ 84 } 85 86 .socialButtons { 87 display: flex; 88 flex-direction: column; /* Stack social buttons vertically */ 89 align-items: center; /* Center them horizontally */ 90 } 91 92 .socialButton { 93 display: inline-flex; /* Align text and image inline */ 94 align-items: center; /* Vertically center content */ 95 justify-content: flex-start; /* Align items to the left */ 96 padding: 10px 15px; 97 border: none; 98 border-radius: 8px; 99 cursor: pointer; 100 font-size: 0.8rem; 101 font-weight: bold; 102 transition: background-color 0.2s, transform 0.2s; 103 width: 100%; 104 max-width: 350px; /* Limit max width */ 105 } 106 107 .socialButton img { 108 width: 20px; 109 height: 20px; 110 margin-right: 10px; 111 vertical-align: middle; 112 } 113 114 .socialButton:hover { 115 filter: brightness(95%); 116 } 117 118 .socialButton:active { 119 transform: scale(0.98); 120 } 121 122 .socialButton:nth-child(2) { 123 background-color: #333; /* GitHub button */ 124 color: white; 125 } 126 127 .socialButton:nth-child(1) { 128 background-color: #ffffff; /* Google button */ 129 color: #000000; 130 box-shadow: 1px 2px #2f2525; 72 131 } 73 132 74 133 @media (min-width: 542px) { 75 134 body { 76 display: -webkit-box;77 display: -ms-flexbox;78 135 display: flex; 79 -webkit-box-pack: center;80 -ms-flex-pack: center;81 136 justify-content: center; 82 137 } 138 83 139 .wrapper { 84 display: -webkit-box;85 display: -ms-flexbox;86 140 display: flex; 87 141 height: 100vh; 88 -webkit-box-align: center;89 -ms-flex-align: center;90 142 align-items: center; 91 -ms-flex-pack: distribute; 92 justify-content: space-around; 93 padding: 1.5rem; 143 justify-content: flex-end; /* Keep the form to the right */ 144 padding: 2rem; 94 145 max-width: 1100px; 95 146 } 147 96 148 .form { 97 -ms-flex-preferred-size: auto;98 149 flex-basis: auto; 99 } 150 align-items: center; /* Center form in larger screens */ 151 width: 100%; 152 max-width: 400px; /* Keep form max width consistent */ 153 } 154 100 155 .form input { 101 width: 250px; 102 } 156 width: 100%; /* Ensures the input expands fully */ 157 max-width: 350px; 158 } 159 160 .illustration{ 161 margin-right: 40%; 162 } 163 103 164 .illustration img { 104 max-width: 80%;165 max-width: 100%; 105 166 height: auto; 106 167 } … … 108 169 109 170 @media (max-width: 680px) { 171 .wrapper { 172 flex-direction: column; /* Stack form and illustration vertically */ 173 align-items: center; /* Center content horizontally */ 174 padding: 1rem; 175 } 176 110 177 .illustration { 111 display: none; 112 } 113 } 114 115 .signUp .illustration { 116 order: 2; 117 justify-self: flex-end; 118 margin-left: 2rem; 178 display: none; /* Hide the illustration on mobile */ 179 } 180 181 .form { 182 width: 100%; /* Full width for mobile */ 183 align-items: center; /* Center form elements horizontally */ 184 } 185 186 .form input, 187 .form button, 188 .socialButton { 189 width: 100%; /* Full width for mobile */ 190 max-width: 300px; /* Optional: Limit max width */ 191 } 119 192 } 120 193 … … 126 199 transform: scale(0.98); 127 200 } 201 202 .error { 203 color: red; 204 font-size: 0.9rem; 205 margin-top: 0.5rem; 206 }
Note:
See TracChangeset
for help on using the changeset viewer.