d41e8b0372
I have no idea where the FRONTEND environment variable came from (I think it's from my original write of Commento v1, which had whole bunch of different terminologies). Anyway, the `os.Getenv("FRONTEND")` would basically amount to nothing all the time, and it would redirect to "/login" irrespective of whether the user has a subdirectory-based COMMENTO_ORIGIN value. Closes https://gitlab.com/commento/commento-ce/issues/72
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func ownerConfirmHex(confirmHex string) error {
|
|
if confirmHex == "" {
|
|
return errorMissingField
|
|
}
|
|
|
|
statement := `
|
|
UPDATE owners
|
|
SET confirmedEmail=true
|
|
WHERE ownerHex IN (
|
|
SELECT ownerHex FROM ownerConfirmHexes
|
|
WHERE confirmHex=$1
|
|
);
|
|
`
|
|
res, err := db.Exec(statement, confirmHex)
|
|
if err != nil {
|
|
logger.Errorf("cannot mark user's confirmedEmail as true: %v\n", err)
|
|
return errorInternal
|
|
}
|
|
|
|
count, err := res.RowsAffected()
|
|
if err != nil {
|
|
logger.Errorf("cannot count rows affected: %v\n", err)
|
|
return errorInternal
|
|
}
|
|
|
|
if count == 0 {
|
|
return errorNoSuchConfirmationToken
|
|
}
|
|
|
|
statement = `
|
|
DELETE FROM ownerConfirmHexes
|
|
WHERE confirmHex=$1;
|
|
`
|
|
_, err = db.Exec(statement, confirmHex)
|
|
if err != nil {
|
|
logger.Warningf("cannot remove confirmation token: %v\n", err)
|
|
// Don't return an error because this is not critical.
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func ownerConfirmHexHandler(w http.ResponseWriter, r *http.Request) {
|
|
if confirmHex := r.FormValue("confirmHex"); confirmHex != "" {
|
|
if err := ownerConfirmHex(confirmHex); err == nil {
|
|
http.Redirect(w, r, fmt.Sprintf("%s/login?confirmed=true", os.Getenv("ORIGIN")), http.StatusTemporaryRedirect)
|
|
return
|
|
}
|
|
}
|
|
|
|
// TODO: include error message in the URL
|
|
http.Redirect(w, r, fmt.Sprintf("%s/login?confirmed=false", os.Getenv("ORIGIN")), http.StatusTemporaryRedirect)
|
|
}
|