2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-31 14:05:14 +00:00

Implemented user/change_email.

This commit is contained in:
Edho Arief
2012-06-27 21:07:15 +07:00
parent 4328a7d33b
commit d0a9a8de7c
6 changed files with 50 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ class UserController < ApplicationController
before_filter :janitor_only, :only => [:invites]
before_filter :mod_only, :only => [:block, :unblock, :show_blocked_users]
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 :avatar
auto_complete_for :user, :name
@@ -24,6 +24,11 @@ class UserController < ApplicationController
@title = 'Change Password'
end
def change_email
@title = 'Change Email'
@current_user.current_email = @current_user.email
end
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] + "%"])
render :layout => false, :text => "<ul>" + @users.map {|x| "<li>" + x.name + "</li>"}.join("") + "</ul>"

View File

@@ -2,6 +2,7 @@ require 'digest/sha1'
class User < ActiveRecord::Base
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
module UserBlacklistMethods
@@ -78,7 +79,7 @@ class User < ActiveRecord::Base
# 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
# 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?
errors.add :current_password, :blank
elsif User.authenticate(self.name, current_password).nil?

View 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" %>

View File

@@ -20,7 +20,7 @@
</tr>
<tr>
<th>
<label class="block" for="user_email"><%=t :user3 %></label>
<%= t('.email') %>
<% if CONFIG["enable_account_email_activation"] %>
<p><%=t :user4 %></p>
<% else %>
@@ -28,7 +28,7 @@
<% end %>
</th>
<td>
<%= text_field "user", "email", :size => 40 %>
<%= @user.email.blank? ? t('.no_email') : @user.email %> (<%= link_to t('.update_email'), :action => :change_email %>)
</td>
</tr>
<tr>

View File

@@ -30,6 +30,14 @@ en:
user:
change_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:
not_logged_in: You are not logged in.
login: Login

View File

@@ -8,6 +8,9 @@ Moebooru::Application.routes.draw do
end
end
# User
match 'user/change_email'
# API 1.13.0
scope :defaults => { :format => 'html' }, :constraints => { :format => /(json|xml|html)/, :id => /\d+/ } do
# Posts