fixes #1651
This commit is contained in:
18
app/controllers/maintenance/user/email_changes_controller.rb
Normal file
18
app/controllers/maintenance/user/email_changes_controller.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Maintenance
|
||||
module User
|
||||
class EmailChangesController < ApplicationController
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
email_change = UserEmailChange.new(CurrentUser.user, params[:email_change][:email], params[:email_change][:password])
|
||||
if email_change.process
|
||||
redirect_to(edit_user_path(CurrentUser.user.id), :notice => "Email was updated")
|
||||
else
|
||||
flash[:notice] = "Password was incorrect"
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
18
app/logical/user_email_change.rb
Normal file
18
app/logical/user_email_change.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class UserEmailChange
|
||||
attr_reader :user, :password, :new_email
|
||||
|
||||
def initialize(user, new_email, password)
|
||||
@user = user
|
||||
@new_email = new_email
|
||||
@password = password
|
||||
end
|
||||
|
||||
def process
|
||||
if User.authenticate(user.name, password).nil?
|
||||
false
|
||||
else
|
||||
user.email = new_email
|
||||
user.save
|
||||
end
|
||||
end
|
||||
end
|
||||
19
app/views/maintenance/user/email_changes/new.html.erb
Normal file
19
app/views/maintenance/user/email_changes/new.html.erb
Normal file
@@ -0,0 +1,19 @@
|
||||
<h1>Change Email</h1>
|
||||
|
||||
<p>You must confirm your password in order to change your email address.</p>
|
||||
|
||||
<%= form_tag(maintenance_user_email_change_path, :class => "simple_form") do %>
|
||||
<div class="input">
|
||||
<label>New Email</label>
|
||||
<%= email_field :email_change, :email %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label>Password</label>
|
||||
<%= password_field :email_change, :password %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= submit_tag "Submit" %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -15,7 +15,19 @@
|
||||
<p>You must <%= link_to "upgrade your account", upgrade_information_users_path %> to request a name change</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<%= f.input :email, :required => Danbooru.config.enable_email_verification?, :hint => "Used for messages and for password resets", :as => :email %>
|
||||
|
||||
<div class="input">
|
||||
<label>Email</label>
|
||||
<p>
|
||||
<% if CurrentUser.user.email.present? %>
|
||||
<%= CurrentUser.user.email %>
|
||||
<% else %>
|
||||
<em>blank</em>
|
||||
<% end %>
|
||||
–
|
||||
<%= link_to "Change your email", new_maintenance_user_email_change_path %></p>
|
||||
</div>
|
||||
|
||||
<%= f.input :time_zone, :include_blank => false %>
|
||||
<%= f.input :receive_email_notifications, :as => :select, :include_blank => false %>
|
||||
<%= f.input :comment_threshold, :hint => "Comments below this score will be hidden by default" %>
|
||||
@@ -52,7 +64,7 @@
|
||||
<fieldset>
|
||||
<legend>Delete Account</legend>
|
||||
<div class="input">
|
||||
<p><%= link_to "Click here to delete your account", maintenance_user_deletion_path %></p>
|
||||
<p><%= link_to "Delete your account", maintenance_user_deletion_path %></p>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user