11package main
22
33import (
4- "bytes"
54 "fmt"
6- "image/png"
75 "io/ioutil"
86 "net/http"
97 "os"
108 "regexp"
119 "strings"
1210
1311 "github.com/julienschmidt/httprouter"
14- "github.com/pquerna/otp/totp"
1512 "golang.org/x/crypto/bcrypt"
1613
1714 qrcode "github.com/skip2/go-qrcode"
@@ -232,7 +229,6 @@ func signinHandler(w *Web) {
232229
233230 email := strings .ToLower (strings .TrimSpace (w .r .FormValue ("email" )))
234231 password := w .r .FormValue ("password" )
235- passcode := w .r .FormValue ("totp" )
236232
237233 if email != config .FindInfo ().Email {
238234 w .Redirect ("/signin?error=invalid" )
@@ -243,13 +239,6 @@ func signinHandler(w *Web) {
243239 w .Redirect ("/signin?error=invalid" )
244240 return
245241 }
246-
247- if config .FindInfo ().TotpKey != "" && ! totp .Validate (passcode , config .FindInfo ().TotpKey ) {
248- // Totp has been configured and the provided code doesn't match
249- w .Redirect ("/signin?error=invalid" )
250- return
251- }
252-
253242 if err := w .SigninSession (true , "" ); err != nil {
254243 Error (w .w , err )
255244 return
@@ -258,36 +247,6 @@ func signinHandler(w *Web) {
258247 w .Redirect ("/" )
259248}
260249
261- func totpQRHandler (w * Web ) {
262- if ! w .Admin {
263- Error (w .w , fmt .Errorf ("failed to view config: permission denied" ))
264- return
265- }
266-
267- if config .Info .TotpKey != "" {
268- // TOTP is already configured, don't allow the current one to be leaked
269- w .Redirect ("/" )
270- return
271- }
272-
273- var buf bytes.Buffer
274- img , err := tempTotpKey .Image (200 , 200 )
275- if err != nil {
276- Error (w .w , err )
277- return
278- }
279-
280- png .Encode (& buf , img )
281-
282- w .w .Header ().Set ("Content-Type" , "image/png" )
283- w .w .Header ().Set ("Content-Length" , fmt .Sprintf ("%d" , len (buf .Bytes ())))
284- if _ , err := w .w .Write (buf .Bytes ()); err != nil {
285- Error (w .w , err )
286- return
287- }
288-
289- }
290-
291250func userEditHandler (w * Web ) {
292251 userID := w .ps .ByName ("user" )
293252 if userID == "" {
@@ -579,9 +538,6 @@ func settingsHandler(w *Web) {
579538 currentPassword := w .r .FormValue ("current_password" )
580539 newPassword := w .r .FormValue ("new_password" )
581540
582- resetTotp := w .r .FormValue ("reset_totp" )
583- totpCode := w .r .FormValue ("totp_code" )
584-
585541 config .UpdateInfo (func (i * Info ) error {
586542 i .SAML .IDPMetadata = samlMetadata
587543 i .Email = email
@@ -621,26 +577,6 @@ func settingsHandler(w *Web) {
621577 })
622578 }
623579
624- if resetTotp == "true" {
625- err := config .ResetTotp ()
626- if err != nil {
627- w .Redirect ("/settings?error=totp" )
628- return
629- }
630-
631- w .Redirect ("/settings?success=totp" )
632- return
633- }
634-
635- if config .Info .TotpKey == "" && totpCode != "" {
636- if ! totp .Validate (totpCode , tempTotpKey .Secret ()) {
637- w .Redirect ("/settings?error=totp" )
638- return
639- }
640- config .Info .TotpKey = tempTotpKey .Secret ()
641- config .save ()
642- }
643-
644580 w .Redirect ("/settings?success=settings" )
645581}
646582
0 commit comments