@ -20,6 +20,7 @@ import (
"sync"
"sync"
"time"
"time"
"github.com/gorilla/csrf"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"github.com/gorilla/sessions"
"github.com/guregu/null/zero"
"github.com/guregu/null/zero"
@ -1082,6 +1083,7 @@ func viewSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) err
HasPass bool
HasPass bool
IsLogOut bool
IsLogOut bool
Silenced bool
Silenced bool
CSRFField template . HTML
OauthSection bool
OauthSection bool
OauthAccounts [ ] oauthAccountInfo
OauthAccounts [ ] oauthAccountInfo
OauthSlack bool
OauthSlack bool
@ -1098,6 +1100,7 @@ func viewSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) err
HasPass : passIsSet ,
HasPass : passIsSet ,
IsLogOut : r . FormValue ( "logout" ) == "1" ,
IsLogOut : r . FormValue ( "logout" ) == "1" ,
Silenced : fullUser . IsSilenced ( ) ,
Silenced : fullUser . IsSilenced ( ) ,
CSRFField : csrf . TemplateField ( r ) ,
OauthSection : displayOauthSection ,
OauthSection : displayOauthSection ,
OauthAccounts : oauthAccounts ,
OauthAccounts : oauthAccounts ,
OauthSlack : enableOauthSlack ,
OauthSlack : enableOauthSlack ,
@ -1152,6 +1155,32 @@ func getTempInfo(app *App, key string, r *http.Request, w http.ResponseWriter) s
return s
return s
}
}
func handleUserDelete ( app * App , u * User , w http . ResponseWriter , r * http . Request ) error {
if ! app . cfg . App . OpenDeletion {
return impart . HTTPError { http . StatusForbidden , "Open account deletion is disabled on this instance." }
}
confirmUsername := r . PostFormValue ( "confirm-username" )
if u . Username != confirmUsername {
return impart . HTTPError { http . StatusBadRequest , "Confirmation username must match your username exactly." }
}
// Check for account deletion safeguards in place
if u . IsAdmin ( ) {
return impart . HTTPError { http . StatusForbidden , "Cannot delete admin." }
}
err := app . db . DeleteAccount ( u . ID )
if err != nil {
log . Error ( "user delete account: %v" , err )
return impart . HTTPError { http . StatusInternalServerError , fmt . Sprintf ( "Could not delete account: %v" , err ) }
}
// FIXME: This doesn't ever appear to the user, as (I believe) the value is erased when the session cookie is reset
_ = addSessionFlash ( app , w , r , "Thanks for writing with us! You account was deleted successfully." , nil )
return impart . HTTPError { http . StatusFound , "/me/logout" }
}
func removeOauth ( app * App , u * User , w http . ResponseWriter , r * http . Request ) error {
func removeOauth ( app * App , u * User , w http . ResponseWriter , r * http . Request ) error {
provider := r . FormValue ( "provider" )
provider := r . FormValue ( "provider" )
clientID := r . FormValue ( "client_id" )
clientID := r . FormValue ( "client_id" )
@ -1173,6 +1202,7 @@ func prepareUserEmail(input string, emailKey []byte) zero.String {
log . Error ( "Unable to encrypt email: %s\n" , err )
log . Error ( "Unable to encrypt email: %s\n" , err )
} else {
} else {
email . String = string ( encEmail )
email . String = string ( encEmail )
}
}
}
}
return email
return email