Skip to content

Commit

Permalink
Add email edit
Browse files Browse the repository at this point in the history
  • Loading branch information
binkoni committed Feb 14, 2020
1 parent b832e1d commit dc62ba9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
13 changes: 13 additions & 0 deletions applications/user.moon
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class MoonRocksUser extends lapis.Application

assert_valid @params, {
{"profile", type: "table"}
{"email", type: "string"}
}

profile = trim_filter @params.profile,
Expand All @@ -312,6 +313,18 @@ class MoonRocksUser extends lapis.Application
data: difference
}

if @user.email != @params.email
old_email = @user.email
@user\update_email @params.email
import UserActivityLogs from require "models"

UserActivityLogs\create_from_request @, {
user_id: @user.id
source: "web"
action: "account.update_email"
data: {old_email, @user.email}
}

redirect_to: @url_for "user_settings.profile"

}
Expand Down
7 changes: 2 additions & 5 deletions models/user_activity_logs.moon
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ class UserActivityLogs extends Model
table.insert parts, "set #{k}"

table.concat parts, ", "
when "account.update_email"
"updated email from #{@data[1]} to #{@data[2]}"
when "account.update_password_attempt"
@data.reason
when "account.create_api_key", "account.revoke_api_key"
if @data.key
@data.key\sub(1, 10) .. ""





1 change: 1 addition & 0 deletions models/user_sessions.moon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class UserSessions extends Model
admin: 4
login_github: 5
register_github: 6
update_email: 7
}

@create_from_request: (req, user, more_params) =>
Expand Down
11 changes: 11 additions & 0 deletions models/users.moon
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ class Users extends Model
order by similarity(username, ?) desc
]], query, query, per_page: 50

update_email: (email, r) =>
dupemail = Users\find [db.raw "lower(email)"]: email\lower!
return nil, "duplicate email" unless dupemail == nil

@update email: email
if r
if r.current_user_session
r.current_user_session\revoke!
@write_session r, type: "update_email"
return true

update_password: (pass, r) =>
@update encrypted_password: bcrypt.digest pass, bcrypt.salt 5
if r
Expand Down
11 changes: 11 additions & 0 deletions views/user_settings/profile.moon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ class UserSettingsProfile extends require "widgets.user_settings_page"
@csrf_input!
data = @user\get_data!

div class: "row", ->
label ->
div class: "label", "Your email"

input {
type: "text"
class: "medium_input"
name: "email"
value: @user.email
}

div class: "row", ->
label ->
div class: "label", "Your website"
Expand Down

0 comments on commit dc62ba9

Please sign in to comment.