mirror of
https://github.com/moebooru/moebooru
synced 2025-09-04 07:55:13 +00:00
Implemented user/change_email.
This commit is contained in:
@@ -7,7 +7,7 @@ class UserController < ApplicationController
|
|||||||
before_filter :janitor_only, :only => [:invites]
|
before_filter :janitor_only, :only => [:invites]
|
||||||
before_filter :mod_only, :only => [:block, :unblock, :show_blocked_users]
|
before_filter :mod_only, :only => [:block, :unblock, :show_blocked_users]
|
||||||
before_filter :post_member_only, :only => [:set_avatar]
|
before_filter :post_member_only, :only => [:set_avatar]
|
||||||
before_filter :no_anonymous, :only => [:change_password]
|
before_filter :no_anonymous, :only => [:change_password, :change_email]
|
||||||
helper :post, :tag_subscription
|
helper :post, :tag_subscription
|
||||||
helper :avatar
|
helper :avatar
|
||||||
auto_complete_for :user, :name
|
auto_complete_for :user, :name
|
||||||
@@ -24,6 +24,11 @@ class UserController < ApplicationController
|
|||||||
@title = 'Change Password'
|
@title = 'Change Password'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def change_email
|
||||||
|
@title = 'Change Email'
|
||||||
|
@current_user.current_email = @current_user.email
|
||||||
|
end
|
||||||
|
|
||||||
def auto_complete_for_member_name
|
def auto_complete_for_member_name
|
||||||
@users = User.find(:all, :order => "lower(name)", :conditions => ["level = ? AND name ILIKE ? ESCAPE E'\\\\'", CONFIG["user_levels"]["Member"], params[:member][:name] + "%"])
|
@users = User.find(:all, :order => "lower(name)", :conditions => ["level = ? AND name ILIKE ? ESCAPE E'\\\\'", CONFIG["user_levels"]["Member"], params[:member][:name] + "%"])
|
||||||
render :layout => false, :text => "<ul>" + @users.map {|x| "<li>" + x.name + "</li>"}.join("") + "</ul>"
|
render :layout => false, :text => "<ul>" + @users.map {|x| "<li>" + x.name + "</li>"}.join("") + "</ul>"
|
||||||
|
@@ -2,6 +2,7 @@ require 'digest/sha1'
|
|||||||
|
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
scope :name_starts_with, lambda { |s| where User.arel_table[:name].matches("#{s}*".to_escaped_for_sql_like) }
|
scope :name_starts_with, lambda { |s| where User.arel_table[:name].matches("#{s}*".to_escaped_for_sql_like) }
|
||||||
|
attr_accessor :current_email
|
||||||
class AlreadyFavoritedError < Exception; end
|
class AlreadyFavoritedError < Exception; end
|
||||||
|
|
||||||
module UserBlacklistMethods
|
module UserBlacklistMethods
|
||||||
@@ -78,7 +79,7 @@ class User < ActiveRecord::Base
|
|||||||
# First test to see if it's creating new user (no password_hash)
|
# First test to see if it's creating new user (no password_hash)
|
||||||
# or updating user. The second is to see if the action involves
|
# or updating user. The second is to see if the action involves
|
||||||
# updating password (which requires this validation).
|
# updating password (which requires this validation).
|
||||||
if self.password_hash and password
|
if self.password_hash and (password or (self.email_changed? or current_email))
|
||||||
if current_password.blank?
|
if current_password.blank?
|
||||||
errors.add :current_password, :blank
|
errors.add :current_password, :blank
|
||||||
elsif User.authenticate(self.name, current_password).nil?
|
elsif User.authenticate(self.name, current_password).nil?
|
||||||
|
29
app/views/user/change_email.html.erb
Normal file
29
app/views/user/change_email.html.erb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<div id="user-edit">
|
||||||
|
<%= form_for @current_user, :url => { :action => :update } do |f| %>
|
||||||
|
<%= hidden_field :render, :view, :value => :change_email %>
|
||||||
|
<%-# Just so the current email carries over on error -%>
|
||||||
|
<%= f.hidden_field :current_email %>
|
||||||
|
<%= render 'shared/error_messages', :object => f.object %>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th><%= t('.current_email') %></th>
|
||||||
|
<td><%= @current_user.current_email %></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><%= f.label :email, t('.new_email') %></th>
|
||||||
|
<td><%= f.text_field :email %></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><%= f.label t('.current_password') %></th>
|
||||||
|
<td><%= f.password_field :current_password %></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><%= f.submit t('buttons.save') %> <%= f.submit t('buttons.cancel') %></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render :partial => "footer" %>
|
@@ -20,7 +20,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
<label class="block" for="user_email"><%=t :user3 %></label>
|
<%= t('.email') %>
|
||||||
<% if CONFIG["enable_account_email_activation"] %>
|
<% if CONFIG["enable_account_email_activation"] %>
|
||||||
<p><%=t :user4 %></p>
|
<p><%=t :user4 %></p>
|
||||||
<% else %>
|
<% else %>
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<%= text_field "user", "email", :size => 40 %>
|
<%= @user.email.blank? ? t('.no_email') : @user.email %> (<%= link_to t('.update_email'), :action => :change_email %>)
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@@ -30,6 +30,14 @@ en:
|
|||||||
user:
|
user:
|
||||||
change_password:
|
change_password:
|
||||||
new_password: New password
|
new_password: New password
|
||||||
|
change_email:
|
||||||
|
current_password: Current password
|
||||||
|
current_email: Current Email
|
||||||
|
new_email: New Email
|
||||||
|
edit:
|
||||||
|
email: Email
|
||||||
|
no_email: none
|
||||||
|
update_email: Change
|
||||||
home:
|
home:
|
||||||
not_logged_in: You are not logged in.
|
not_logged_in: You are not logged in.
|
||||||
login: Login
|
login: Login
|
||||||
|
@@ -8,6 +8,9 @@ Moebooru::Application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# User
|
||||||
|
match 'user/change_email'
|
||||||
|
|
||||||
# API 1.13.0
|
# API 1.13.0
|
||||||
scope :defaults => { :format => 'html' }, :constraints => { :format => /(json|xml|html)/, :id => /\d+/ } do
|
scope :defaults => { :format => 'html' }, :constraints => { :format => /(json|xml|html)/, :id => /\d+/ } do
|
||||||
# Posts
|
# Posts
|
||||||
|
Reference in New Issue
Block a user