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 @@
- <%= form_for @user, url: {action: "changepasswd"} do |f| %> - <%= render 'shared/error_messages', object: f.object %> + <%= form_tag("/changepasswd", method: "post") do %>
- - <%= text_field_tag("verif_code", class: 'form-control', placeholder: "请输入邮箱验证码") %> +
- - <%= f.email_field :email, class: 'form-control', placeholder: "请输入邮箱" %> +
- - <%= f.password_field :password, class: 'form-control', placeholder: "请输入密码" %> +
-
- - <%= f.password_field :password_confirmation, class: 'form-control', placeholder: "请再次输入密码" %> +
- <%= f.submit "重置密码", class: "btn btn-primary btn-block" %> + <%= submit_tag "重置密码", class: "btn btn-primary btn-block" %> <% end %> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\ No newline at end of file diff --git a/code.bak b/code.bak new file mode 100644 index 0000000..b1c3dd6 --- /dev/null +++ b/code.bak @@ -0,0 +1,33 @@ + <%= form_for @user, url: {action: "changepasswd"} do |f| %> + <%= render 'shared/error_messages', object: f.object %> + +
+
+ + +
+
+ +
+
+ + <%= f.email_field :email, class: 'form-control', placeholder: "请输入邮箱" %> +
+
+ +
+
+ + <%= f.password_field :password, class: 'form-control', placeholder: "请输入密码" %> +
+
+ +
+
+ + <%= f.password_field :password_confirmation, class: 'form-control', placeholder: "请再次输入密码" %> +
+
+ + <%= f.submit "重置密码", class: "btn btn-primary btn-block" %> + <% end %> \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 161bf35..e9f87de 100644 --- a/config/application.rb +++ b/config/application.rb @@ -17,8 +17,8 @@ module GuorenPro config.action_mailer.smtp_settings = { :address => "smtp.163.com", :port => 25, - :user_name => "zy_lovestar@163.com", - :password => "zy_lovestar+=*", + :user_name => "ucasguoren@163.com", + :password => "ucas123", :authentication => "plain", :enable_starttls_auto => true } diff --git a/config/environments/development.rb b/config/environments/development.rb index 3ad1cba..cc257de 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -57,8 +57,8 @@ Rails.application.configure do config.action_mailer.smtp_settings = { :address => "smtp.163.com", :port => 25, - :user_name => "zy_lovestar@163.com", - :password => "zy_lovestar+=*", + :user_name => "ucasguoren@163.com", + :password => "ucas123", :authentication => "plain", :enable_starttls_auto => true } diff --git a/config/routes.rb b/config/routes.rb index fbb0f4c..374c6e7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,7 @@ Rails.application.routes.draw do get '/profile', to: 'users#edit' get '/forgetpasswd', to: 'users#forgetpasswd' get '/changepasswd', to: 'users#changepasswd' + post '/changepasswd', to: 'users#changepasswd' get '/main', to: 'main#show' get '/activity', to: 'main#activity' diff --git a/db/development.sqlite3 b/db/development.sqlite3 index a6f22eb..8bc8f0b 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ