2008年12月4日木曜日

restful_authenticationで、メールアドレスを使ってログインする。

つうか、ね?
今どき、ログインIDでのログインって、在り得なくない?
普通に、メールアドレスでログインだよね?
つうか、:loginって、いらなくね?

つう訳で、restful_authentication howto, step-by-step (part 2)を参考に、いじった。

で、もう、ソースを書き写すのが面倒臭くってwww
diffです。
app/models/user.rb

-  validates_presence_of     :login
-  validates_length_of       :login,    :within => 3..40
-  validates_uniqueness_of   :login
-  validates_format_of       :login,    :with => Authentication.login_regex, :message => :bad_login_message
+#  validates_presence_of     :login
+#  validates_length_of       :login,    :within => 3..40
+#  validates_uniqueness_of   :login
+#  validates_format_of       :login,    :with => Authentication.login_regex, :message => :bad_login_message

-    attr_accessible :login, :email, :name, :password, :password_confirmation
+    attr_accessible :email, :name, :password, :password_confirmation

-    u = find_in_state :first, :active, :conditions => {:login => login} # need to get the salt
+#    u = find_in_state :first, :active, :conditions => {:login => login} # need to get the salt
+    u = find_in_state :first, :active, :conditions => {:email => login} # need to get the salt

app/controllers/sessions_controller.rb

-    user = User.authenticate(params[:login], params[:password])
+    user = User.authenticate(params[:email], params[:password])

app/views/users/_user_bar.html.erb

-   <div id="user-bar-greeting">Logged in as <%= link_to_current_user :content_method => :login %></div>
+   <div id="user-bar-greeting">

+   </div>

app/views/users/new.html.erb

-<p><%= label_tag 'login', t('actionview.label.common.login') %><br/>
-<%= f.text_field :login %></p>

app/views/user_mailer/signup_notification.erb

-   Username: <%=h @user.login %>
+   Email: <%=h @user.email %>

 app/views/sessions/new.html.erb

-<p><%= label_tag 'login', t('actionview.label.common.login') %><br />
-<%= text_field_tag 'login', @login %></p>
+<p><%= label_tag 'email', t('actionview.label.common.email') %><br />
+<%= text_field_tag 'email', @login %></p>


こんな感じ?
じゃあ、usersモデルから、loginカラムを削っちゃおう。
$ script/generate migration RemoveLoginFromUsers login:string
マイグレーションついでに、DBをリセットしましょうか。
$ rake db:migrate:reset
こんな感じで。
で、新規登録し直して、script/serverのログから認証url拾ってきて、ログインして、おk?
おk。

0 件のコメント: