6
6
< title > Scratch Auth | Login & Dashboard | Coding Hut</ title >
7
7
< style >
8
8
body {
9
- font-family : ' Arial' , sans-serif;
9
+ font-family : Arial, sans-serif;
10
10
margin : 0 ;
11
11
padding : 0 ;
12
12
background-color : # f4f4f4 ;
18
18
padding : 20px ;
19
19
box-shadow : 0 2px 5px rgba (0 , 0 , 0 , 0.2 );
20
20
}
21
- .content {
21
+ .content , . container {
22
22
padding : 20px ;
23
23
max-width : 600px ;
24
- margin : auto;
24
+ margin : 20 px auto;
25
25
background-color : white;
26
26
border-radius : 8px ;
27
27
box-shadow : 0 2px 10px rgba (0 , 0 , 0 , 0.1 );
32
32
margin-top : 10px ;
33
33
}
34
34
button {
35
- padding : 10px 20px ;
36
- margin : 10px ;
35
+ width : 100% ;
36
+ padding : 12px 20px ;
37
+ margin : 10px 0 ;
37
38
font-size : 16px ;
38
39
border : none;
39
40
border-radius : 5px ;
45
46
button : hover {
46
47
background-color : # a03a3a ;
47
48
}
49
+ input {
50
+ width : 100% ;
51
+ padding : 12px ;
52
+ margin : 10px 0 ;
53
+ border : 1px solid # ddd ;
54
+ border-radius : 5px ;
55
+ font-size : 16px ;
56
+ }
48
57
p {
49
58
line-height : 1.5 ;
50
59
}
51
60
a {
52
61
text-decoration : none;
62
+ color : white;
53
63
}
54
64
</ style >
55
65
< script >
66
+ const serverUrl = 'https://image-hoster.onrender.com' ;
67
+
56
68
function registerScratchAuth ( ) {
57
69
const messageBox = document . getElementById ( "message" ) ;
58
-
59
70
const redirectLocation = encodeURIComponent ( window . location . href ) ;
60
71
const authUrl = `https://auth.itinerary.eu.org/auth/?redirect=${ redirectLocation } &name=Coding%20Hut&sign_in_method=cloud` ;
61
72
62
73
messageBox . style . color = "green" ;
63
- messageBox . textContent = ` Redirecting to Scratch Auth... Follow the steps there.` ;
74
+ messageBox . textContent = " Redirecting to Scratch Auth... Follow the steps there." ;
64
75
65
76
setTimeout ( ( ) => {
66
77
window . location . href = authUrl ;
69
80
70
81
function checkAuth ( ) {
71
82
const urlParams = new URLSearchParams ( window . location . search ) ;
72
- const authSuccess = urlParams . get ( 'success' ) ; // Example: Scratch Auth might return '?success=true'
83
+ const authSuccess = urlParams . get ( 'success' ) ;
73
84
const username = urlParams . get ( 'username' ) ;
85
+
74
86
if ( username ) {
75
87
localStorage . setItem ( 'username' , username ) ;
76
88
}
82
94
}
83
95
84
96
window . onload = checkAuth ;
97
+
98
+ if ( localStorage . getItem ( 'verifiedUser' ) ) {
99
+ window . location . href = 'index.html' ;
100
+ }
101
+
102
+ async function login ( ) {
103
+ let username = document . getElementById ( 'username' ) . value . trim ( ) . toLowerCase ( ) ;
104
+ if ( ! username ) {
105
+ alert ( 'Enter your Scratch username.' ) ;
106
+ return ;
107
+ }
108
+
109
+ const response = await fetch ( `${ serverUrl } /login` , {
110
+ method : 'POST' ,
111
+ headers : { 'Content-Type' : 'application/json' } ,
112
+ body : JSON . stringify ( { username } )
113
+ } ) ;
114
+
115
+ const result = await response . json ( ) ;
116
+ if ( result . verified ) {
117
+ localStorage . setItem ( 'verifiedUser' , username ) ;
118
+ window . location . href = 'upload.html' ;
119
+ } else {
120
+ document . getElementById ( 'codeMessage' ) . textContent = result . message || 'Login failed. Please try again.' ;
121
+ }
122
+ }
123
+
124
+ async function verifyCode ( ) {
125
+ let username = document . getElementById ( 'username' ) . value . trim ( ) . toLowerCase ( ) ;
126
+ if ( ! username ) {
127
+ alert ( 'Enter your username first.' ) ;
128
+ return ;
129
+ }
130
+
131
+ const response = await fetch ( `${ serverUrl } /verify` , {
132
+ method : 'POST' ,
133
+ headers : { 'Content-Type' : 'application/json' } ,
134
+ body : JSON . stringify ( { username } )
135
+ } ) ;
136
+
137
+ const result = await response . json ( ) ;
138
+ if ( result . verified ) {
139
+ localStorage . setItem ( 'verifiedUser' , username ) ;
140
+ window . location . href = 'index.html' ;
141
+ } else {
142
+ alert ( result . message || 'Verification failed. Please try again.' ) ;
143
+ }
144
+ }
85
145
</ script >
86
146
</ head >
87
147
< body >
88
148
< div class ="header ">
89
149
< h1 > Scratch Authentication</ h1 >
90
150
</ div >
151
+
91
152
< div class ="content ">
92
153
< h2 > Welcome! Please log in to continue.</ h2 >
93
- < button onclick ="registerScratchAuth() "> Register With ScratchAuth (Currently not working.)</ button >
94
-
95
- <!DOCTYPE html>
96
- < html lang ="en ">
97
- < head >
98
- < meta charset ="UTF-8 ">
99
- < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
100
- < title > Login</ title >
101
- < style >
102
- body { font-family : Arial, sans-serif; background : # f4f4f4 ; display : flex; align-items : center; justify-content : center; height : 100vh ; }
103
- .container { background : # fff ; padding : 20px ; border-radius : 10px ; box-shadow : 0 4px 10px rgba (0 , 0 , 0 , 0.1 ); text-align : center; width : 350px ; }
104
- input , button { width : 100% ; padding : 10px ; margin : 10px 0 ; border : 1px solid # ddd ; border-radius : 5px ; font-size : 16px ; }
105
- button { background : # 007bff ; color : white; border : none; cursor : pointer; }
106
- </ style >
107
- </ head >
108
- < body >
109
- < div class ="container ">
110
- < button onclick ="login() "> Login With APIAuth (Made by < a href ="scratch.mit.edu/users/kRxZy_kRxZy>kRxZy_kRxZy</a>)</button>
111
- <p id= "codeMessage "> </ p >
112
- < button onclick ="verifyCode() "> Done</ button >
113
- </ div >
154
+ < button onclick ="registerScratchAuth() "> Register With ScratchAuth</ button >
114
155
< p id ="message " class ="message " aria-live ="polite "> </ p >
115
156
< p >
116
157
Please note: You will be redirected to an external site (Scratch Auth) for authentication. Once there,
@@ -122,51 +163,14 @@ <h2>Welcome! Please log in to continue.</h2>
122
163
< a href ="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new ">
123
164
< button > Having trouble signing in? Report an issue</ button >
124
165
</ a >
125
- < script >
126
- const serverUrl = 'https://image-hoster.onrender.com' ;
127
-
128
- if ( localStorage . getItem ( 'verifiedUser' ) ) {
129
- window . location . href = 'index' ;
130
- }
131
-
132
- async function login ( ) {
133
- let username = document . getElementById ( 'username' ) . value . trim ( ) . toLowerCase ( ) ;
134
- if ( ! username ) return alert ( 'Enter your Scratch username.' ) ;
135
-
136
- const response = await fetch ( `${ serverUrl } /login` , {
137
- method : 'POST' ,
138
- headers : { 'Content-Type' : 'application/json' } ,
139
- body : JSON . stringify ( { username } )
140
- } ) ;
141
-
142
- const result = await response . json ( ) ;
143
- if ( result . verified ) {
144
- localStorage . setItem ( 'verifiedUser' , username ) ;
145
- window . location . href = 'upload.html' ;
146
- } else {
147
- document . getElementById ( 'codeMessage' ) . textContent = result . message ;
148
- }
149
- }
150
-
151
- async function verifyCode ( ) {
152
- let username = document . getElementById ( 'username' ) . value . trim ( ) . toLowerCase ( ) ;
153
- if ( ! username ) return alert ( 'Enter your username first.' ) ;
154
-
155
- const response = await fetch ( `${ serverUrl } /verify` , {
156
- method : 'POST' ,
157
- headers : { 'Content-Type' : 'application/json' } ,
158
- body : JSON . stringify ( { username } )
159
- } ) ;
166
+ </ div >
160
167
161
- const result = await response . json ( ) ;
162
- if ( result . verified ) {
163
- localStorage . setItem ( 'verifiedUser' , username ) ;
164
- window . location . href = 'index.html' ;
165
- } else {
166
- alert ( result . message || 'Verification failed.' ) ;
167
- }
168
- }
169
- </ script >
168
+ < div class ="container ">
169
+ < h2 > Login Using APIAuth</ h2 >
170
+ < input type ="text " id ="username " placeholder ="Enter your Scratch username " />
171
+ < button onclick ="login() "> Login With APIAuth (Made by < a href ="https://scratch.mit.edu/users/kRxZy_kRxZy/ " target ="_blank " style ="color: red "> kRxZy_kRxZy</ a > )</ button >
172
+ < p id ="codeMessage " class ="message "> </ p >
173
+ < button onclick ="verifyCode() "> Verify Code</ button >
170
174
</ div >
171
175
</ body >
172
176
</ html >
0 commit comments