修改密码接口
This commit is contained in:
parent
41fa6f02f1
commit
96004b3270
|
@ -179,17 +179,35 @@ class MyController < ApplicationController
|
|||
return
|
||||
end
|
||||
if request.post?
|
||||
if @user.check_password?(params[:password])
|
||||
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
|
||||
if @user.save
|
||||
us = UsersService.new
|
||||
@user = us.change_password params.merge(:current_user_id => @user.id)
|
||||
if @user.errors.full_messages.count <= 0
|
||||
flash.now[:notice] = l(:notice_account_password_updated)
|
||||
redirect_to my_account_url
|
||||
end
|
||||
else
|
||||
end
|
||||
rescue Exception => e
|
||||
if e.message == 'wrong password'
|
||||
flash.now[:error] = l(:notice_account_wrong_password)
|
||||
end
|
||||
end
|
||||
# @user = User.current
|
||||
# unless @user.change_password_allowed?
|
||||
# flash.now[:error] = l(:notice_can_t_change_password)
|
||||
# redirect_to my_account_url
|
||||
# return
|
||||
# end
|
||||
# if request.post?
|
||||
# if @user.check_password?(params[:password])
|
||||
# @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
#
|
||||
# if @user.save
|
||||
# flash.now[:notice] = l(:notice_account_password_updated)
|
||||
# redirect_to my_account_url
|
||||
# end
|
||||
# else
|
||||
# flash.now[:error] = l(:notice_account_wrong_password)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
# Create a new feeds key
|
||||
|
|
|
@ -111,4 +111,19 @@ class UsersService
|
|||
User.watched_by(@user.id)
|
||||
end
|
||||
|
||||
#修改密码
|
||||
def change_password params
|
||||
@current_user = User.find(params[:current_user_id])
|
||||
if @current_user.check_password?(params[:password])
|
||||
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
@current_user.save
|
||||
#raise @current_user.errors.full_message
|
||||
#return @current_user
|
||||
|
||||
else
|
||||
raise 'wrong password'
|
||||
end
|
||||
@current_user
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue