@@ -153,6 +153,11 @@ func doLogin(username, password string) (string, error) {
153
153
154
154
// LoginGet renders the login form
155
155
func LoginGet (w http.ResponseWriter , r * http.Request ) {
156
+ loginForm (w , r , "" )
157
+ }
158
+
159
+ // loginForm renders the login form
160
+ func loginForm (w http.ResponseWriter , r * http.Request , errMsg string ) {
156
161
log .Write ("Login page" )
157
162
tmpl := template .New ("layout" )
158
163
tmpl , err := tmpl .Parse (templates .Layout )
@@ -170,11 +175,13 @@ func LoginGet(w http.ResponseWriter, r *http.Request) {
170
175
year , _ , _ := time .Now ().Date ()
171
176
srvcfg := config .Read ()
172
177
data := struct {
173
- GinURL string
174
- CurrentYear int
178
+ GinURL string
179
+ CurrentYear int
180
+ ErrorMessage string
175
181
}{
176
182
srvcfg .GINAddresses .WebURL ,
177
183
year ,
184
+ errMsg ,
178
185
}
179
186
tmpl .Execute (w , & data )
180
187
}
@@ -187,13 +194,13 @@ func LoginPost(w http.ResponseWriter, r *http.Request) {
187
194
password := r .FormValue ("password" )
188
195
if username == "" || password == "" {
189
196
log .Write ("[error] Invalid form data" )
190
- fail (w , http . StatusUnauthorized , "authentication failed" )
197
+ loginForm (w , r , "Authentication failed" )
191
198
return
192
199
}
193
200
sessionid , err := doLogin (username , password )
194
201
if err != nil {
195
202
log .Write ("[error] Login failed: %s" , err .Error ())
196
- fail (w , http . StatusUnauthorized , "authentication failed" )
203
+ loginForm (w , r , "Authentication failed" )
197
204
return
198
205
}
199
206
0 commit comments