let users change their password william nilliam
This commit is contained in:
@ -116,6 +116,11 @@ app:post("user_delete", "/:username/delete", function(self)
|
||||
return {redirect_to = self:url_for("user", {username = self.params.username})}
|
||||
end
|
||||
|
||||
if me:is_admin() then
|
||||
util.inject_err_infobox("You can not delete the admin account!")
|
||||
return {redirect_to = self:url_for("user", {username = self.params.username})}
|
||||
end
|
||||
|
||||
if not authenticate_user(target_user, self.params.password) then
|
||||
util.inject_err_infobox(self, "The password you entered is incorrect.")
|
||||
return {redirect_to = self:url_for("user_delete_confirm", {username = me.username})}
|
||||
@ -199,6 +204,35 @@ app:post("user_set_avatar", "/:username/set_avatar", function(self)
|
||||
return {redirect_to = self:url_for("user_settings", {username = self.params.username})}
|
||||
end)
|
||||
|
||||
app:post("user_change_password", "/:username/new_password", function(self)
|
||||
local me = util.get_logged_in_user(self)
|
||||
if not me then
|
||||
return {redirect_to = self:url_for("user_settings", {username = self.params.username})}
|
||||
end
|
||||
local target_user = Users:find({username = self.params.username})
|
||||
if me.id ~= target_user.id then
|
||||
return {redirect_to = self:url_for("user", {username = self.params.username})}
|
||||
end
|
||||
local password = self.params.new_password
|
||||
local password2 = self.params.new_password2
|
||||
if not validate_password(password) then
|
||||
util.inject_err_infobox(self, "Password must be 10+ chars with: 1 uppercase, 1 lowercase, 1 number, 1 special char, and no spaces.")
|
||||
return {redirect_to = self:url_for("user_settings", {username = self.params.username})}
|
||||
end
|
||||
|
||||
if password ~= password2 then
|
||||
util.inject_err_infobox(self, "Passwords do not match.")
|
||||
return {redirect_to = self:url_for("user_settings", {username = self.params.username})}
|
||||
end
|
||||
|
||||
me:update({
|
||||
password_hash = auth.digest(password)
|
||||
})
|
||||
util.extend_session_cookie(self)
|
||||
util.inject_infobox(self, "Password updated.")
|
||||
return {redirect_to = self:url_for("user_settings", {username = self.params.username})}
|
||||
end)
|
||||
|
||||
app:get("user_settings", "/:username/settings", function(self)
|
||||
local me = util.get_logged_in_user(self)
|
||||
if me == nil then
|
||||
@ -345,6 +379,7 @@ app:post("user_logout", "/logout", function (self)
|
||||
|
||||
local session = Sessions:find({key = self.session.session_key})
|
||||
session:delete()
|
||||
self.session = nil
|
||||
return {redirect_to = self:url_for("user_login")}
|
||||
end)
|
||||
|
||||
|
Reference in New Issue
Block a user