diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 10e093a..6636045 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -34,7 +34,7 @@ class UsersController < ApplicationController if useremail @user = User.find_by(email: useremail) if !@user.nil? - # send_code @user + send_code @user flash[:success] = "验证码已发送至您的邮箱" redirect_to changepasswd_path(email: @user.email) else @@ -53,10 +53,21 @@ class UsersController < ApplicationController @user = User.find_by(email: user_email) if !@user.nil? render 'changepasswd' + else + flash[:danger] = "用户不存在" + redirect_to login_path end + else + redirect_to login_path end else - render html: "hello" + result = check_change_params(params[:email], params[:verify_code], params[:password], params[:password_confirm]) + if result + flash[:success]="密码更新成功" + else + flash[:danger]="密码更新失败" + end + redirect_to login_path end end @@ -77,7 +88,24 @@ class UsersController < ApplicationController user.verify_code = verify_code user.save end + end + def check_change_params(email, verify_code, password, password_confirmation) + if password != password_confirmation + return false + end + user = User.find_by(email: email) + if user.nil? + return false + end + if user.verify_code != verify_code + return false + end + hold = Hash.new + hold[:password] = password + hold[:password_confirmation] = password_confirmation + user.update_attributes(hold) + return true end end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..0937a52 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' + default from: "ucasguoren@163.com" layout 'mailer' end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index bf1e057..afb5a78 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,5 +1,5 @@ class UserMailer < ApplicationMailer - default from: "zy_lovestar@163.com" + default from: "ucasguoren@163.com" def send_verify_code mail_address, code @verify_code = code diff --git a/app/views/users/changepasswd.html.erb b/app/views/users/changepasswd.html.erb index efe2b45..243d518 100644 --- a/app/views/users/changepasswd.html.erb +++ b/app/views/users/changepasswd.html.erb @@ -4,79 +4,44 @@