zy: add verify code
This commit is contained in:
parent
2c21dc9142
commit
92821cfd87
|
@ -29,6 +29,39 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def forgetpasswd
|
||||||
|
useremail = params[:email]
|
||||||
|
if useremail
|
||||||
|
@user = User.find_by(email: useremail)
|
||||||
|
if !@user.nil?
|
||||||
|
# send_code @user
|
||||||
|
flash[:success] = "验证码已发送至您的邮箱"
|
||||||
|
redirect_to changepasswd_path(email: @user.email)
|
||||||
|
else
|
||||||
|
flash[:danger] = "用户不存在"
|
||||||
|
render 'forgetpasswd'
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render 'forgetpasswd'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def changepasswd
|
||||||
|
if request.get?
|
||||||
|
user_email = params[:email]
|
||||||
|
if user_email
|
||||||
|
@user = User.find_by(email: user_email)
|
||||||
|
if !@user.nil?
|
||||||
|
render 'changepasswd'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render html: "hello"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
|
@ -36,4 +69,15 @@ class UsersController < ApplicationController
|
||||||
:password_confirmation)
|
:password_confirmation)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def send_code user
|
||||||
|
verify_code = rand(999999).to_s
|
||||||
|
result = UserMailer.send_verify_code(user.email, verify_code).deliver_now
|
||||||
|
p result
|
||||||
|
User.transaction do
|
||||||
|
user.verify_code = verify_code
|
||||||
|
user.save
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
class UserMailer < ApplicationMailer
|
||||||
|
default from: "zy_lovestar@163.com"
|
||||||
|
|
||||||
|
def send_verify_code mail_address, code
|
||||||
|
@verify_code = code
|
||||||
|
mail(to: mail_address, subject: "验证码")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -8,8 +8,8 @@
|
||||||
<%= form_tag(controller: "login", action: "login", method: "post") do %>
|
<%= form_tag(controller: "login", action: "login", method: "post") do %>
|
||||||
<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><input class="form-control"
|
<span class="input-group-addon"><i class="icon-user"></i></span><input class="form-control"
|
||||||
placeholder="请输入登陆账号"
|
placeholder="请输入登陆邮箱"
|
||||||
name="email"
|
name="email"
|
||||||
type="text">
|
type="text">
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,9 +22,9 @@
|
||||||
type="password">
|
type="password">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a class="pull-right" href="#">忘记密码?</a>
|
<a class="pull-right" href="/forgetpasswd">忘记密码?</a>
|
||||||
<div class="text-left">
|
<div class="text-left">
|
||||||
<label class="checkbox"><input type="checkbox" name="remember" ><span>记住我</span></label>
|
<label class="checkbox"><input type="checkbox" name="remember"><span>记住我</span></label>
|
||||||
</div>
|
</div>
|
||||||
<input class="btn btn-lg btn-primary btn-block" type="submit" value="登陆">
|
<input class="btn btn-lg btn-primary btn-block" type="submit" value="登陆">
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<!-- 新 Bootstrap 核心 CSS 文件 -->
|
||||||
|
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
|
||||||
|
|
||||||
|
<!-- 可选的Bootstrap主题文件(一般不用引入) -->
|
||||||
|
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
|
||||||
|
|
||||||
|
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
|
||||||
|
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
|
||||||
|
|
||||||
|
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
|
||||||
|
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
您的验证码是: <%= @verify_code %>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -0,0 +1,82 @@
|
||||||
|
<% provide(:title, '忘记密码') %>
|
||||||
|
<% provide(:body_class, 'login2') %>
|
||||||
|
|
||||||
|
<div class="login-wrapper">
|
||||||
|
<a href="#"><img width="210" height="70" src="images/logo/guoren.png"/></a>
|
||||||
|
|
||||||
|
<%= 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-ok"></i></span>
|
||||||
|
<%= text_field_tag("verif_code", class: 'form-control', placeholder: "请输入邮箱验证码") %>
|
||||||
|
</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 %>
|
||||||
|
|
||||||
|
<!--<%= 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>
|
|
@ -2,33 +2,33 @@
|
||||||
|
|
||||||
<div class="modal-shiftfix">
|
<div class="modal-shiftfix">
|
||||||
|
|
||||||
<div id="profile-container" class="container-fluid main-content">
|
<div id="profile-container" class="container-fluid main-content">
|
||||||
|
|
||||||
<%= render 'layouts/nav' %>
|
<%= render 'layouts/nav' %>
|
||||||
|
|
||||||
<form action="/baidu" class="form-horizontal" id="profile" method="post">
|
<form action="/baidu" class="form-horizontal" id="profile" method="post">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="widget-container">
|
<div class="widget-container">
|
||||||
<div class="heading">
|
<div class="heading">
|
||||||
<i class="icon-user"></i>个人设置
|
<i class="icon-user"></i>个人设置
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="widget-container">
|
||||||
<div class="widget-container">
|
<div class="heading">
|
||||||
<div class="heading">
|
<i class="icon-user"></i>用户图像
|
||||||
<i class="icon-user"></i>用户图像
|
</div>
|
||||||
</div>
|
<div class="col-md-12 text-center">
|
||||||
<div class="col-md-12 text-center">
|
<div class="fileupload fileupload-new" data-provides="fileupload">
|
||||||
<div class="fileupload fileupload-new" data-provides="fileupload">
|
<div class="fileupload-new img-thumbnail" style="width: 200px; height: 200px;">
|
||||||
<div class="fileupload-new img-thumbnail" style="width: 200px; height: 200px;">
|
<!--原照片-->
|
||||||
<!--原照片-->
|
<img src="/images/avatars/default/avatar.png">
|
||||||
<img src="/images/avatars/default/avatar.png">
|
</div>
|
||||||
</div>
|
<div class="fileupload-preview fileupload-exists img-thumbnail"
|
||||||
<div class="fileupload-preview fileupload-exists img-thumbnail"
|
style="width: 200px; max-height: 200px">
|
||||||
style="width: 200px; max-height: 200px">
|
</div>
|
||||||
</div>
|
<div class="padded">
|
||||||
<div class="padded">
|
|
||||||
<span class="btn btn-default btn-file">
|
<span class="btn btn-default btn-file">
|
||||||
<span
|
<span
|
||||||
class="fileupload-new">选择照片
|
class="fileupload-new">选择照片
|
||||||
|
@ -39,70 +39,70 @@
|
||||||
</span>
|
</span>
|
||||||
<input type="file" name="image_file">
|
<input type="file" name="image_file">
|
||||||
</span>
|
</span>
|
||||||
<a
|
<a
|
||||||
class="btn btn-default fileupload-exists" data-dismiss="fileupload"
|
class="btn btn-default fileupload-exists" data-dismiss="fileupload"
|
||||||
href="#">清除照片
|
href="#">清除照片
|
||||||
</a>
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="widget-container fluid-height clearfix">
|
||||||
<div class="widget-container fluid-height clearfix">
|
<div class="heading">
|
||||||
<div class="heading">
|
<i class="icon-reorder"></i>基本信息
|
||||||
<i class="icon-reorder"></i>基本信息
|
|
||||||
</div>
|
|
||||||
<div class="padded">
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="control-label col-md-2">姓名</label>
|
|
||||||
<div class="col-md-9">
|
|
||||||
<input class="form-control" placeholder="Text" type="text">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="padded">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label col-md-2">专业</label>
|
<label class="control-label col-md-2">姓名</label>
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
<input class="form-control" placeholder="Text" type="text">
|
<input class="form-control" placeholder="Text" type="text">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
<div class="form-group">
|
<label class="control-label col-md-2">专业</label>
|
||||||
<label class="control-label col-md-2">学院</label>
|
<div class="col-md-9">
|
||||||
<div class="col-md-9">
|
<input class="form-control" placeholder="Text" type="text">
|
||||||
<select class="form-control">
|
</div>
|
||||||
<option value="Category 1">Option 1</option>
|
|
||||||
<option value="Category 2">Option 2</option>
|
|
||||||
<option value="Category 3">Option 3</option>
|
|
||||||
<option value="Category 4">Option 4</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="control-label col-md-2">性别</label>
|
<div class="form-group">
|
||||||
<div class="col-md-9">
|
<label class="control-label col-md-2">学院</label>
|
||||||
<label class="radio-inline"><input name="optionsRadios" type="radio"
|
<div class="col-md-9">
|
||||||
value="1"><span>男</span></label><label
|
<select class="form-control">
|
||||||
class="radio-inline"><input name="optionsRadios"
|
<option value="Category 1">Option 1</option>
|
||||||
type="radio"
|
<option value="Category 2">Option 2</option>
|
||||||
value="0"><span>女</span></label>
|
<option value="Category 3">Option 3</option>
|
||||||
|
<option value="Category 4">Option 4</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-md-12 text-center">
|
<label class="control-label col-md-2">性别</label>
|
||||||
<button class="btn btn-primary" type="submit">修改</button>
|
<div class="col-md-9">
|
||||||
<button class="btn btn-default-outline">取消</button>
|
<label class="radio-inline"><input name="optionsRadios" type="radio"
|
||||||
|
value="1"><span>男</span></label><label
|
||||||
|
class="radio-inline"><input name="optionsRadios"
|
||||||
|
type="radio"
|
||||||
|
value="0"><span>女</span></label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-12 text-center">
|
||||||
|
<button class="btn btn-primary" type="submit">修改</button>
|
||||||
|
<button class="btn btn-default-outline">取消</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -0,0 +1,22 @@
|
||||||
|
<% provide(:title, '忘记密码') %>
|
||||||
|
<% provide(:body_class, 'login2') %>
|
||||||
|
|
||||||
|
<div class="login-wrapper">
|
||||||
|
<a href="#"><img width="210" height="70" src="images/logo/guoren.png"/></a>
|
||||||
|
|
||||||
|
<%= form_tag("/forgetpasswd", method: "get") 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>
|
||||||
|
|
||||||
|
<%= submit_tag "找回密码", class: "btn btn-primary btn-block" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
|
@ -12,5 +12,15 @@ module GuorenPro
|
||||||
# Application configuration should go into files in config/initializers
|
# Application configuration should go into files in config/initializers
|
||||||
# -- all .rb files in that directory are automatically loaded.
|
# -- all .rb files in that directory are automatically loaded.
|
||||||
config.time_zone = 'Beijing'
|
config.time_zone = 'Beijing'
|
||||||
|
config.action_mailer.delivery_method = :smtp
|
||||||
|
config.action_mailer.raise_delivery_errors = true
|
||||||
|
config.action_mailer.smtp_settings = {
|
||||||
|
:address => "smtp.163.com",
|
||||||
|
:port => 25,
|
||||||
|
:user_name => "zy_lovestar@163.com",
|
||||||
|
:password => "zy_lovestar+=*",
|
||||||
|
:authentication => "plain",
|
||||||
|
:enable_starttls_auto => true
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,4 +51,15 @@ Rails.application.configure do
|
||||||
# Use an evented file watcher to asynchronously detect changes in source code,
|
# Use an evented file watcher to asynchronously detect changes in source code,
|
||||||
# routes, locales, etc. This feature depends on the listen gem.
|
# routes, locales, etc. This feature depends on the listen gem.
|
||||||
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
||||||
|
|
||||||
|
config.action_mailer.delivery_method = :smtp
|
||||||
|
config.action_mailer.raise_delivery_errors = true
|
||||||
|
config.action_mailer.smtp_settings = {
|
||||||
|
:address => "smtp.163.com",
|
||||||
|
:port => 25,
|
||||||
|
:user_name => "zy_lovestar@163.com",
|
||||||
|
:password => "zy_lovestar+=*",
|
||||||
|
:authentication => "plain",
|
||||||
|
:enable_starttls_auto => true
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
get '/signup', to: 'users#new'
|
get '/signup', to: 'users#new'
|
||||||
get '/profile', to: 'users#edit'
|
get '/profile', to: 'users#edit'
|
||||||
|
get '/forgetpasswd', to: 'users#forgetpasswd'
|
||||||
|
get '/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.
|
@ -0,0 +1,5 @@
|
||||||
|
class AddVerifyCodeToUsers < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
add_column :users, :verify_code, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20161227034933) do
|
ActiveRecord::Schema.define(version: 20170102130110) do
|
||||||
|
|
||||||
create_table "comments", force: :cascade do |t|
|
create_table "comments", force: :cascade do |t|
|
||||||
t.string "content"
|
t.string "content"
|
||||||
|
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20161227034933) do
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "password_digest"
|
t.string "password_digest"
|
||||||
|
t.string "verify_code"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
|
||||||
|
class UserMailerPreview < ActionMailer::Preview
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class UserMailerTest < ActionMailer::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in New Issue