Skip to content

Commit 8d4a9dd

Browse files
committed
Merge pull request #30 from fusion94/master
Username support
2 parents ae3f5a3 + a39ddbc commit 8d4a9dd

20 files changed

+177
-10
lines changed

app/assets/javascripts/backbone/plugins/me_announce.js.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ class Kandan.Plugins.MeAnnounce
55

66
@init: ()->
77
Kandan.Modifiers.register @options.regex, (message, state) =>
8-
actor = message.user.first_name || message.user.email
8+
actor = message.user.username || message.user.email
99
message.content = message.content.replace @options.regex, "#{actor} "
1010
return Kandan.Helpers.Activities.buildFromBaseTemplate(message)

app/assets/javascripts/backbone/plugins/user_list.js.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Kandan.Plugins.UserList
1717

1818
for user in Kandan.Data.ActiveUsers.all()
1919
displayName = null
20-
displayName = "#{user.first_name} #{user.last_name}" if user.first_name?
21-
displayName ||= user.email # Default to user email address if that's all we have
20+
displayName = user.username # Defaults to username
21+
displayName ||= user.email # Revert to user email address if that's all we have
2222

2323
$users.append @template({
2424
name: displayName,

app/assets/templates/message.jst.eco

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<div class="readable">
77
<span class="user">
8-
<%= @activity.user.first_name || @activity.user.email %>
8+
<%= @activity.user.username || @activity.user.email %>
99
</span>
1010

1111
<span class="content">

app/assets/templates/user_notification.jst.eco

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<span class="user">Kandan bot</span>
88

99
<span class="content">
10-
<%= @activity.user.first_name || @activity.user.email %> <%= @activity.action %>ed <%- "<a href='#{@activity.content}'>#{@activity.content}</a>" if @activity.action == "upload" %>
10+
<%= @activity.user.username || @activity.user.email %> <%= @activity.action %>ed <%- "<a href='#{@activity.content}'>#{@activity.content}</a>" if @activity.action == "upload" %>
1111
</span>
1212
</div>
1313

app/models/user.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class User < ActiveRecord::Base
99
devise devise *Kandan.devise_modules
1010

1111
# Setup accessible (or protected) attributes for your model
12-
attr_accessible :id, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :locale, :gravatar_hash
12+
attr_accessible :id, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :locale, :gravatar_hash
1313

1414
def cloudfuji_extra_attributes(extra_attributes)
1515
self.first_name = extra_attributes["first_name"].to_s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h2>Resend confirmation instructions</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email %></div>
8+
9+
<div><%= f.submit "Resend confirmation instructions" %></div>
10+
<% end %>
11+
12+
<%= render :partial => "devise/shared/links" %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>Welcome <%= @resource.email %>!</p>
2+
3+
<p>You can confirm your account through the link below:</p>
4+
5+
<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<p>Hello <%= @resource.email %>!</p>
2+
3+
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
4+
5+
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
6+
7+
<p>If you didn't request this, please ignore this email.</p>
8+
<p>Your password won't change until you access the link above and create a new one.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<p>Hello <%= @resource.email %>!</p>
2+
3+
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
4+
5+
<p>Click the link below to unlock your account:</p>
6+
7+
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<h2>Change your password</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
4+
<%= devise_error_messages! %>
5+
<%= f.hidden_field :reset_password_token %>
6+
7+
<div><%= f.label :password, "New password" %><br />
8+
<%= f.password_field :password %></div>
9+
10+
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
11+
<%= f.password_field :password_confirmation %></div>
12+
13+
<div><%= f.submit "Change my password" %></div>
14+
<% end %>
15+
16+
<%= render :partial => "devise/shared/links" %>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h2>Forgot your password?</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email %></div>
8+
9+
<div><%= f.submit "Send me reset password instructions" %></div>
10+
<% end %>
11+
12+
<%= render :partial => "devise/shared/links" %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<h2>Edit <%= resource_name.to_s.humanize %></h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email %></div>
8+
9+
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
10+
<%= f.password_field :password %></div>
11+
12+
<div><%= f.label :password_confirmation %><br />
13+
<%= f.password_field :password_confirmation %></div>
14+
15+
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
16+
<%= f.password_field :current_password %></div>
17+
18+
<div><%= f.submit "Update" %></div>
19+
<% end %>
20+
21+
<h3>Cancel my account</h3>
22+
23+
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
24+
25+
<%= link_to "Back", :back %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<h3>Register an Account</h3>
2+
3+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email %></div>
8+
9+
<div><%= f.label :username %><br />
10+
<%= f.text_field :username %></div>
11+
12+
<div><%= f.label :password %><br />
13+
<%= f.password_field :password %></div>
14+
15+
<div><%= f.label :password_confirmation %><br />
16+
<%= f.password_field :password_confirmation %></div>
17+
18+
<div><%= f.submit "Register" %></div>
19+
<% end %>
20+
21+
<%= render :partial => "devise/shared/links" %>
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h2>Sign in</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
4+
<div><%= f.label :username %><br />
5+
<%= f.text_field :username %></div>
6+
7+
<div><%= f.label :password %><br />
8+
<%= f.password_field :password %></div>
9+
10+
<% if devise_mapping.rememberable? -%>
11+
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
12+
<% end -%>
13+
14+
<div><%= f.submit "Sign in" %></div>
15+
<% end %>
16+
17+
<%= render :partial => "devise/shared/links" %>

app/views/devise/shared/_links.erb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%- if controller_name != 'sessions' %>
2+
<%= link_to "Sign in", new_session_path(resource_name) %><br />
3+
<% end -%>
4+
5+
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6+
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
7+
<% end -%>
8+
9+
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10+
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11+
<% end -%>
12+
13+
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14+
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15+
<% end -%>
16+
17+
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18+
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19+
<% end -%>
20+
21+
<%- if devise_mapping.omniauthable? %>
22+
<%- resource_class.omniauth_providers.each do |provider| %>
23+
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
24+
<% end -%>
25+
<% end -%>

app/views/devise/unlocks/new.html.erb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h2>Resend unlock instructions</h2>
2+
3+
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
4+
<%= devise_error_messages! %>
5+
6+
<div><%= f.label :email %><br />
7+
<%= f.email_field :email %></div>
8+
9+
<div><%= f.submit "Resend unlock instructions" %></div>
10+
<% end %>
11+
12+
<%= render :partial => "devise/shared/links" %>

app/views/layouts/application.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
:first_name => current_user.first_name,
2121
:last_name => current_user.last_name,
2222
:email => current_user.email,
23+
:username => current_user.username,
2324
:auth_token => current_user.authentication_token,
2425
:gravatar_hash => current_user.gravatar_hash
2526
}

config/initializers/devise.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# session. If you need permissions, you should implement that in a before filter.
2626
# You can also supply a hash where the value is a boolean determining whether
2727
# or not authentication should be aborted when the value is not present.
28-
# config.authentication_keys = [ :email ]
28+
config.authentication_keys = [ :username ]
2929

3030
# Configure parameters from the request object used for authentication. Each entry
3131
# given should be a request method and it will automatically be passed to the
@@ -37,12 +37,12 @@
3737
# Configure which authentication keys should be case-insensitive.
3838
# These keys will be downcased upon creating or modifying a user and when used
3939
# to authenticate or find a user. Default is :email.
40-
config.case_insensitive_keys = [ :email ]
40+
config.case_insensitive_keys = [ :username ]
4141

4242
# Configure which authentication keys should have whitespace stripped.
4343
# These keys will have whitespace before and after removed upon creating or
4444
# modifying a user and when used to authenticate or find a user. Default is :email.
45-
config.strip_whitespace_keys = [ :email ]
45+
config.strip_whitespace_keys = [ :username ]
4646

4747
# Tell if authentication through request.params is enabled. True by default.
4848
# config.params_authenticatable = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddUsernameToUsers < ActiveRecord::Migration
2+
def change
3+
add_column :users, :username, :string
4+
end
5+
end

db/schema.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 20120404114631) do
14+
ActiveRecord::Schema.define(:version => 20130125210407) do
1515

1616
create_table "activities", :force => true do |t|
1717
t.text "content"
@@ -70,6 +70,7 @@
7070
t.datetime "updated_at", :null => false
7171
t.text "gravatar_hash"
7272
t.boolean "active", :default => true
73+
t.string "username"
7374
end
7475

7576
add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true

0 commit comments

Comments
 (0)