zy: add mail send code to change password
This commit is contained in:
parent
92821cfd87
commit
d20cb8ec83
|
@ -34,7 +34,7 @@ class UsersController < ApplicationController
|
||||||
if useremail
|
if useremail
|
||||||
@user = User.find_by(email: useremail)
|
@user = User.find_by(email: useremail)
|
||||||
if !@user.nil?
|
if !@user.nil?
|
||||||
# send_code @user
|
send_code @user
|
||||||
flash[:success] = "验证码已发送至您的邮箱"
|
flash[:success] = "验证码已发送至您的邮箱"
|
||||||
redirect_to changepasswd_path(email: @user.email)
|
redirect_to changepasswd_path(email: @user.email)
|
||||||
else
|
else
|
||||||
|
@ -53,10 +53,21 @@ class UsersController < ApplicationController
|
||||||
@user = User.find_by(email: user_email)
|
@user = User.find_by(email: user_email)
|
||||||
if !@user.nil?
|
if !@user.nil?
|
||||||
render 'changepasswd'
|
render 'changepasswd'
|
||||||
end
|
else
|
||||||
|
flash[:danger] = "用户不存在"
|
||||||
|
redirect_to login_path
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render html: "hello"
|
redirect_to login_path
|
||||||
|
end
|
||||||
|
else
|
||||||
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -77,7 +88,24 @@ class UsersController < ApplicationController
|
||||||
user.verify_code = verify_code
|
user.verify_code = verify_code
|
||||||
user.save
|
user.save
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class ApplicationMailer < ActionMailer::Base
|
class ApplicationMailer < ActionMailer::Base
|
||||||
default from: 'from@example.com'
|
default from: "ucasguoren@163.com"
|
||||||
layout 'mailer'
|
layout 'mailer'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class UserMailer < ApplicationMailer
|
class UserMailer < ApplicationMailer
|
||||||
default from: "zy_lovestar@163.com"
|
default from: "ucasguoren@163.com"
|
||||||
|
|
||||||
def send_verify_code mail_address, code
|
def send_verify_code mail_address, code
|
||||||
@verify_code = code
|
@verify_code = code
|
||||||
|
|
|
@ -4,79 +4,44 @@
|
||||||
<div class="login-wrapper">
|
<div class="login-wrapper">
|
||||||
<a href="#"><img width="210" height="70" src="images/logo/guoren.png"/></a>
|
<a href="#"><img width="210" height="70" src="images/logo/guoren.png"/></a>
|
||||||
|
|
||||||
<%= form_for @user, url: {action: "changepasswd"} do |f| %>
|
<%= form_tag("/changepasswd", method: "post") do %>
|
||||||
<%= render 'shared/error_messages', object: f.object %>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon"><i class="icon-ok"></i></span>
|
<span class="input-group-addon"><i class="icon-envelope"></i></span><input class="form-control"
|
||||||
<%= text_field_tag("verif_code", class: 'form-control', placeholder: "请输入邮箱验证码") %>
|
placeholder="请输入邮箱地址"
|
||||||
|
name="email"
|
||||||
|
type="email">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon"><i class="icon-envelope"></i></span>
|
<span class="input-group-addon"><i class="icon-envelope-alt"></i></span><input class="form-control"
|
||||||
<%= f.email_field :email, class: 'form-control', placeholder: "请输入邮箱" %>
|
placeholder="请输入邮箱验证码"
|
||||||
|
name="verify_code"
|
||||||
|
type="number">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon"><i class="icon-ok"></i></span>
|
<span class="input-group-addon"><i class="icon-lock"></i></span><input class="form-control"
|
||||||
<%= f.password_field :password, class: 'form-control', placeholder: "请输入密码" %>
|
placeholder="请输入新密码"
|
||||||
|
name="password"
|
||||||
|
type="password">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon"><i class="icon-ok"></i></span>
|
<span class="input-group-addon"><i class="icon-lock"></i></span><input class="form-control"
|
||||||
<%= f.password_field :password_confirmation, class: 'form-control', placeholder: "请再次输入密码" %>
|
placeholder="请再次输入新密码"
|
||||||
|
name="password_confirm"
|
||||||
|
type="password">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= f.submit "重置密码", class: "btn btn-primary btn-block" %>
|
<%= submit_tag "重置密码", class: "btn btn-primary btn-block" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<!--<%= form_tag("/changepasswd", method: "post") do %>-->
|
|
||||||
|
|
||||||
<!--<div class="form-group">-->
|
|
||||||
<!--<div class="input-group">-->
|
|
||||||
<!--<span class="input-group-addon"><i class="icon-envelope"></i></span><input class="form-control"-->
|
|
||||||
<!--placeholder="请输入邮箱地址"-->
|
|
||||||
<!--name="email"-->
|
|
||||||
<!--type="email">-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
||||||
|
|
||||||
<!--<div class="form-group">-->
|
|
||||||
<!--<div class="input-group">-->
|
|
||||||
<!--<span class="input-group-addon"><i class="icon-envelope-alt"></i></span><input class="form-control"-->
|
|
||||||
<!--placeholder="请输入邮箱验证码"-->
|
|
||||||
<!--name="verify_code"-->
|
|
||||||
<!--type="number">-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
||||||
|
|
||||||
<!--<div class="form-group">-->
|
|
||||||
<!--<div class="input-group">-->
|
|
||||||
<!--<span class="input-group-addon"><i class="icon-lock"></i></span><input class="form-control"-->
|
|
||||||
<!--placeholder="请输入新密码"-->
|
|
||||||
<!--name="password"-->
|
|
||||||
<!--type="password">-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--<div class="form-group">-->
|
|
||||||
<!--<div class="input-group">-->
|
|
||||||
<!--<span class="input-group-addon"><i class="icon-lock"></i></span><input class="form-control"-->
|
|
||||||
<!--placeholder="请再次输入新密码"-->
|
|
||||||
<!--name="password_confirm"-->
|
|
||||||
<!--type="password">-->
|
|
||||||
<!--</div>-->
|
|
||||||
<!--</div>-->
|
|
||||||
|
|
||||||
<!--<%= submit_tag "重置密码", class: "btn btn-primary btn-block" %>-->
|
|
||||||
<!--
|
|
||||||
<% end %>-->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
|
@ -0,0 +1,33 @@
|
||||||
|
<%= form_for @user, url: {action: "changepasswd"} do |f| %>
|
||||||
|
<%= render 'shared/error_messages', object: f.object %>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i class="icon-lock"></i></span>
|
||||||
|
<input class="form-control" placeholder="请输入邮箱验证码" name="verify_code" type="text">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i class="icon-envelope"></i></span>
|
||||||
|
<%= f.email_field :email, class: 'form-control', placeholder: "请输入邮箱" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i class="icon-ok"></i></span>
|
||||||
|
<%= f.password_field :password, class: 'form-control', placeholder: "请输入密码" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon"><i class="icon-ok"></i></span>
|
||||||
|
<%= f.password_field :password_confirmation, class: 'form-control', placeholder: "请再次输入密码" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= f.submit "重置密码", class: "btn btn-primary btn-block" %>
|
||||||
|
<% end %>
|
|
@ -17,8 +17,8 @@ module GuorenPro
|
||||||
config.action_mailer.smtp_settings = {
|
config.action_mailer.smtp_settings = {
|
||||||
:address => "smtp.163.com",
|
:address => "smtp.163.com",
|
||||||
:port => 25,
|
:port => 25,
|
||||||
:user_name => "zy_lovestar@163.com",
|
:user_name => "ucasguoren@163.com",
|
||||||
:password => "zy_lovestar+=*",
|
:password => "ucas123",
|
||||||
:authentication => "plain",
|
:authentication => "plain",
|
||||||
:enable_starttls_auto => true
|
:enable_starttls_auto => true
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,8 @@ Rails.application.configure do
|
||||||
config.action_mailer.smtp_settings = {
|
config.action_mailer.smtp_settings = {
|
||||||
:address => "smtp.163.com",
|
:address => "smtp.163.com",
|
||||||
:port => 25,
|
:port => 25,
|
||||||
:user_name => "zy_lovestar@163.com",
|
:user_name => "ucasguoren@163.com",
|
||||||
:password => "zy_lovestar+=*",
|
:password => "ucas123",
|
||||||
:authentication => "plain",
|
:authentication => "plain",
|
||||||
:enable_starttls_auto => true
|
:enable_starttls_auto => true
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ Rails.application.routes.draw do
|
||||||
get '/profile', to: 'users#edit'
|
get '/profile', to: 'users#edit'
|
||||||
get '/forgetpasswd', to: 'users#forgetpasswd'
|
get '/forgetpasswd', to: 'users#forgetpasswd'
|
||||||
get '/changepasswd', to: 'users#changepasswd'
|
get '/changepasswd', to: 'users#changepasswd'
|
||||||
|
post '/changepasswd', to: 'users#changepasswd'
|
||||||
|
|
||||||
get '/main', to: 'main#show'
|
get '/main', to: 'main#show'
|
||||||
get '/activity', to: 'main#activity'
|
get '/activity', to: 'main#activity'
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue