添加重置密码功能
This commit is contained in:
parent
54bdaec347
commit
812c8bc9ff
|
@ -49,7 +49,20 @@ class BlogsController < ApplicationController
|
|||
end
|
||||
|
||||
def update_password
|
||||
|
||||
@user = User.find @current_user.id
|
||||
if @user.check_password(params[:user][:old_password])
|
||||
@user.password = params[:user][:password] || ''
|
||||
@user.password_confirmation = params[:user][:password_confirmation] || ''
|
||||
if @user.save
|
||||
flash[:success] = '修改密码成功,请重新登录'
|
||||
redirect_to login_path
|
||||
else
|
||||
render 'change_password'
|
||||
end
|
||||
else
|
||||
flash.now[:error] = '原密码错误'
|
||||
render 'change_password'
|
||||
end
|
||||
end
|
||||
|
||||
def upload_img
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
.row
|
||||
%h3.set_title 设置
|
||||
= render 'set_sidebar', obj: @user
|
||||
.col-md-8
|
||||
= form_for :user, method: 'post', url: update_password_blogs_path, role: 'form' do |f|
|
||||
.form-group
|
||||
%label{for: 'user_username'} 用户名
|
||||
= f.text_field :username, value: @current_user.username, placeholder: '用户名', class: 'form-control username', disabled: 'disabled'
|
||||
.form-group
|
||||
%label{for: 'user_password'} 旧密码
|
||||
= f.password_field :old_password, placeholder: '旧密码', class: 'form-control password', required: true
|
||||
.form-group
|
||||
%label{for: 'user_password'} 新密码
|
||||
= f.password_field :password, placeholder: '密码,最少6位', class: 'form-control password', required: true
|
||||
.form-group
|
||||
%label{for: 'user_password_confirmation'} 确认密码
|
||||
= f.password_field :password_confirmation, placeholder: '确认密码', class: 'form-control password', required: true
|
||||
= submit_tag '修改', class: 'btn btn-primary set-btn'
|
Loading…
Reference in New Issue