Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/13 user sign up #67

Merged
merged 17 commits into from
Dec 27, 2012
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'pg', :platform => [:ruby, :mswin, :mingw]
gem 'activerecord-jdbcpostgresql-adapter', :platform => [:jruby]

gem 'slim-rails'
gem 'devise'

# Gems used only for assets and not required
# in production environments by default.
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ GEM
multi_json (~> 1.0)
addressable (2.3.2)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bootstrap-sass (2.2.2.0)
sass (~> 3.2)
builder (3.0.4)
Expand All @@ -53,6 +54,11 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.4.0)
devise (2.1.2)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.2.1)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.4.0)
Expand Down Expand Up @@ -91,6 +97,7 @@ GEM
multi_json (1.5.0)
nokogiri (1.5.6)
nokogiri (1.5.6-java)
orm_adapter (0.4.0)
pg (0.14.1)
polyglot (0.3.3)
quiet_assets (1.0.1)
Expand Down Expand Up @@ -172,6 +179,8 @@ GEM
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
warden (1.2.1)
rack (>= 1.0)
websocket (1.0.6)
xpath (1.0.0)
nokogiri (~> 1.3)
Expand All @@ -185,6 +194,7 @@ DEPENDENCIES
bootstrap-sass (~> 2.2.2.0)
capybara
coffee-rails (~> 3.2.1)
devise
factory_girl_rails (~> 4.0)
jasmine (= 1.3.0)
jquery-rails
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
module ApplicationHelper
def resource_name
:user
end

def resource
@resource ||= User.new
end

def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
11 changes: 11 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要 confirmable,注册成功后要给用户发邮件激活。以后发邮件给用户不容易进垃圾箱。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分以后会实现

# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
end
9 changes: 9 additions & 0 deletions app/views/devise/confirmations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h2 Resend confirmation instructions
= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div= f.submit "Resend confirmation instructions"
= render "devise/shared/links"
4 changes: 4 additions & 0 deletions app/views/devise/mailer/confirmation_instructions.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p
| Welcome #{@resource.email}!
p You can confirm your account email through the link below:
p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token)
6 changes: 6 additions & 0 deletions app/views/devise/mailer/reset_password_instructions.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
p
| Hello #{@resource.email}!
p Someone has requested a link to change your password, and you can do this through the link below.
p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token)
p If you didn't request this, please ignore this email.
p Your password won't change until you access the link above and create a new one.
5 changes: 5 additions & 0 deletions app/views/devise/mailer/unlock_instructions.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
p
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock 和 unlock 的也不用了。

| Hello #{@resource.email}!
p Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
p Click the link below to unlock your account:
p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token)
14 changes: 14 additions & 0 deletions app/views/devise/passwords/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
h2 Change your password
= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f|
= devise_error_messages!
= f.hidden_field :reset_password_token
div
= f.label :password, "New password"
br/
= f.password_field :password
div
= f.label :password_confirmation, "Confirm new password"
br/
= f.password_field :password_confirmation
div= f.submit "Change my password"
= render "devise/shared/links"
9 changes: 9 additions & 0 deletions app/views/devise/passwords/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h2 Forgot your password?
= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div= f.submit "Send me reset password instructions"
= render "devise/shared/links"
27 changes: 27 additions & 0 deletions app/views/devise/registrations/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
h2
| Edit #{resource_name.to_s.humanize}
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div
= f.label :password
i (leave blank if you don't want to change it)
br/
= f.password_field :password, :autocomplete => "off"
div
= f.label :password_confirmation
br/
= f.password_field :password_confirmation
div
= f.label :current_password
i (we need your current password to confirm your changes)
br/
= f.password_field :current_password
div= f.submit "Update"
h3 Cancel my account
p
| Unhappy? #{link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete}.
= link_to "Back", :back
17 changes: 17 additions & 0 deletions app/views/devise/registrations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
h2 Sign up
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注册放在首页了,这个文件可以清理

= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div
= f.label :password
br/
= f.password_field :password
div
= f.label :password_confirmation
br/
= f.password_field :password_confirmation
div= f.submit "Sign up"
= render "devise/shared/links"
16 changes: 16 additions & 0 deletions app/views/devise/sessions/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
h2 Sign in
= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
div
= f.label :email
br/
= f.email_field :email
div
= f.label :password
br/
= f.password_field :password
- if devise_mapping.rememberable?
div
= f.check_box :remember_me
= f.label :remember_me
div= f.submit "Sign in"
= render "devise/shared/links"
19 changes: 19 additions & 0 deletions app/views/devise/shared/_links.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- if controller_name != 'sessions'
= link_to "Sign in", new_session_path(resource_name)
br/
- if devise_mapping.registerable? && controller_name != 'registrations'
= link_to "Sign up", new_registration_path(resource_name)
br/
- if devise_mapping.recoverable? && controller_name != 'passwords'
= link_to "Forgot your password?", new_password_path(resource_name)
br/
- if devise_mapping.confirmable? && controller_name != 'confirmations'
= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name)
br/
- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name)
br/
- if devise_mapping.omniauthable?
- resource_class.omniauth_providers.each do |provider|
= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider)
br/
9 changes: 9 additions & 0 deletions app/views/devise/unlocks/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h2 Resend unlock instructions
= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div= f.submit "Resend unlock instructions"
= render "devise/shared/links"
14 changes: 6 additions & 8 deletions app/views/home/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
h1 = t('slogan.title')
p = t('slogan.description')
.span5.offset2
form.login
label = t('label.nickname')
form.login action="/users" accept-charset="UTF-8" id="new_user" method="post"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/users 改成 helper

= devise_error_messages!
input type="text" placeholder=t('label.nickname')
label = t('label.email_address')
input type="text" placeholder=t('label.email_address')
label = t('label.password')
input type="password" placeholder=t('label.password')

button.btn type="submit" = t('label.sign_up')
input#user_email name="user[email]" size="30" type="email" placeholder=t('label.email_address')
input#user_password name="user[password]" size="30" type="password" placeholder=t('label.password')
input#user_password_confirmation name="user[password_confirmation]" size="30" type="password" placeholder=t('label.password_confirmation')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确认密码可以不用了,如果用户输出,登录时还可以通过「忘记密码」找回来。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,这里修改一下

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我又考虑了一下,是否叫username更合适一些,login有时有动词的意思。或者loginname

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就叫 username

input.btn.btn-success name="commit" type="submit" value="#{t('label.sign_up')}"

.row-fluid
.span3
Expand Down
9 changes: 9 additions & 0 deletions app/views/users/confirmations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h2 Resend confirmation instructions
= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div= f.submit "Resend confirmation instructions"
= render "devise/shared/links"
4 changes: 4 additions & 0 deletions app/views/users/mailer/confirmation_instructions.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p
| Welcome #{@resource.email}!
p You can confirm your account email through the link below:
p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token)
6 changes: 6 additions & 0 deletions app/views/users/mailer/reset_password_instructions.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
p
| Hello #{@resource.email}!
p Someone has requested a link to change your password, and you can do this through the link below.
p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token)
p If you didn't request this, please ignore this email.
p Your password won't change until you access the link above and create a new one.
5 changes: 5 additions & 0 deletions app/views/users/mailer/unlock_instructions.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
p
| Hello #{@resource.email}!
p Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
p Click the link below to unlock your account:
p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token)
14 changes: 14 additions & 0 deletions app/views/users/passwords/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
h2 Change your password
= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f|
= devise_error_messages!
= f.hidden_field :reset_password_token
div
= f.label :password, "New password"
br/
= f.password_field :password
div
= f.label :password_confirmation, "Confirm new password"
br/
= f.password_field :password_confirmation
div= f.submit "Change my password"
= render "devise/shared/links"
9 changes: 9 additions & 0 deletions app/views/users/passwords/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h2 Forgot your password?
= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div= f.submit "Send me reset password instructions"
= render "devise/shared/links"
27 changes: 27 additions & 0 deletions app/views/users/registrations/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
h2
| Edit #{resource_name.to_s.humanize}
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div
= f.label :password
i (leave blank if you don't want to change it)
br/
= f.password_field :password, :autocomplete => "off"
div
= f.label :password_confirmation
br/
= f.password_field :password_confirmation
div
= f.label :current_password
i (we need your current password to confirm your changes)
br/
= f.password_field :current_password
div= f.submit "Update"
h3 Cancel my account
p
| Unhappy? #{link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete}.
= link_to "Back", :back
17 changes: 17 additions & 0 deletions app/views/users/registrations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
h2 Sign up
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div
= f.label :password
br/
= f.password_field :password
div
= f.label :password_confirmation
br/
= f.password_field :password_confirmation
div= f.submit "Sign up"
= render "devise/shared/links"
16 changes: 16 additions & 0 deletions app/views/users/sessions/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
h2 Sign in
= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
div
= f.label :email
br/
= f.email_field :email
div
= f.label :password
br/
= f.password_field :password
- if devise_mapping.rememberable?
div
= f.check_box :remember_me
= f.label :remember_me
div= f.submit "Sign in"
= render "devise/shared/links"
19 changes: 19 additions & 0 deletions app/views/users/shared/_links.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- if controller_name != 'sessions'
= link_to "Sign in", new_session_path(resource_name)
br/
- if devise_mapping.registerable? && controller_name != 'registrations'
= link_to "Sign up", new_registration_path(resource_name)
br/
- if devise_mapping.recoverable? && controller_name != 'passwords'
= link_to "Forgot your password?", new_password_path(resource_name)
br/
- if devise_mapping.confirmable? && controller_name != 'confirmations'
= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name)
br/
- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name)
br/
- if devise_mapping.omniauthable?
- resource_class.omniauth_providers.each do |provider|
= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider)
br/
9 changes: 9 additions & 0 deletions app/views/users/unlocks/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h2 Resend unlock instructions
= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f|
= devise_error_messages!
div
= f.label :email
br/
= f.email_field :email
div= f.submit "Resend unlock instructions"
= render "devise/shared/links"