Changeset 1182
- Timestamp:
- 07/11/08 12:38:16 (6 months ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (2 diffs)
- trunk/app/controllers/users_controller.rb (modified) (11 diffs)
- trunk/app/models/mailer.rb (modified) (2 diffs)
- trunk/app/models/user.rb (modified) (1 diff)
- trunk/app/views/mailer/new_password.text.html.rhtml (added)
- trunk/app/views/mailer/new_password.text.plain.rhtml (added)
- trunk/app/views/users/recover_password.rhtml (added)
- trunk/app/views/users/signin.rhtml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r986 r1182 2 2 # Likewise, all the methods added will be available for all controllers. 3 3 class ApplicationController < ActionController::Base 4 before_filter :check_authentication, :except => [:signup, :signin, :welcome, :index, :confirm, :play, :playlist, :feed, :begin, :complete ]4 before_filter :check_authentication, :except => [:signup, :signin, :welcome, :index, :confirm, :play, :playlist, :feed, :begin, :complete, :recover_password] 5 5 6 6 private … … 9 9 redirect_to :controller => "users", :action => "signin" 10 10 end 11 end 11 end 12 12 end trunk/app/controllers/users_controller.rb
r1130 r1182 2 2 open_id_consumer :required => [:email, :nickname], :optional => [:fullname] 3 3 layout 'documents' 4 4 5 5 def index 6 6 welcome 7 7 render(:action => "welcome") 8 8 end 9 9 10 10 def welcome 11 11 # could be remove if no one find something to put in … … 19 19 @tag = user.tags.uniq[0..15] 20 20 end 21 21 22 22 def tags 23 23 user = User.find(session[:user]) … … 27 27 @tag = user.tags.uniq[0..15] 28 28 end 29 29 30 30 def tag 31 31 user = User.find(session[:user]) … … 34 34 @subscription = user.find_subscriptions(:tag => params[:name], :limit => 5) 35 35 end 36 36 37 37 def find 38 38 user = User.find(session[:user]) 39 39 40 40 @document = user.documents.find_by_keywords(params[:keywords]) 41 41 @subscription = user.find_subscriptions(:keywords => params[:keywords]) 42 42 end 43 43 44 44 def options 45 45 @user = User.find(session[:user]) … … 53 53 end 54 54 end 55 55 56 56 def signin 57 57 @user = User.new … … 67 67 end 68 68 end 69 69 70 70 def signup 71 71 @user = User.new(params[:user]) … … 81 81 flash[:failure] = "Votre compte n'a pas été crée" 82 82 end 83 end 83 end 84 84 end 85 85 86 def recover_password 87 @email = params[:email] 88 89 if request.post? 90 user = User.find_by_email(@email) 91 unless user.nil? 92 user.change_password 93 flash[:success] = "Votre nouveau de passe a été envoyé à #{user.email}" 94 redirect_to :action => :signin 95 else 96 flash[:failure] = "Aucun compte AudioBank ne correspond à cet email" 97 end 98 end 99 end 100 86 101 def confirm 87 102 @user = User.find(params[:id]) 88 103 if @user.hashcode == params[:confirm] && !@user.confirmed? 89 104 @user.update_attribute(:confirmed, true) 90 105 91 106 begin 92 107 User.find(@user.id).subscriptions.build(:author => User.find(1), :document => Document.find(1)).save … … 94 109 logger.error("no welcome document found") 95 110 end 96 111 97 112 flash[:success] = "Bienvenue !" 98 113 session[:user] = @user.id … … 118 133 when OpenID::FAILURE 119 134 flash[:failure] = "Votre identification a échoué" 120 135 121 136 when OpenID::SUCCESS 122 137 @user = User.find_or_initialize_by_openid_url(open_id_response.identity_url) … … 130 145 flash[:success] = "Bienvenue !" 131 146 session[:user] = @user.id 132 147 133 148 when OpenID::CANCEL 134 149 flash[:failure] = "Votre identification a été annulé" 135 150 136 151 else 137 152 flash[:failure] = "Voter identification a échoué : #{open_id_response.status}" … … 144 159 flash[:success] = "A bientÃŽt !" 145 160 redirect_to :action => "welcome" 146 end 161 end 147 162 end trunk/app/models/mailer.rb
r1140 r1182 9 9 @body["user"] = user 10 10 end 11 11 12 def new_password(user, new_password) 13 @recipients = user.email 14 @from = "AudioBank <audiobank@tryphon.org>" 15 @subject = "[AudioBank] Votre mot de passe" 16 @body = { :new_password => new_password, :user => user } 17 end 18 12 19 def document_ready(document) 13 20 @recipients = document.author.email … … 16 23 @body = { :document => document, :user => document.author } 17 24 end 18 25 19 26 def document_shared(user, subscriptions) 20 27 return if subscriptions.empty? 21 28 22 29 @recipients = user.email 23 30 @from = "AudioBank <audiobank@tryphon.org>" 24 @subject = 25 "[AudioBank] " + 31 @subject = 32 "[AudioBank] " + 26 33 (subscriptions.size == 1 ? "nouvelle souscription" : "nouvelles souscriptions") 27 34 @body = { :subscriptions => subscriptions, :user => user } 28 35 end 29 36 30 37 end trunk/app/models/user.rb
r1180 r1182 137 137 end 138 138 139 def change_password 140 generated_password = new_password 141 update_attribute(:password, generated_password) 142 Mailer.deliver_new_password(self, generated_password) 143 end 144 145 def new_password 146 random_sha = Digest::SHA256.hexdigest rand.to_s 147 random_sha[-10..-1] 148 end 149 139 150 def match_name?(input) 140 151 (self.name.downcase.include?(input) or (not self.username.nil? and self.username.downcase.include?(input))) trunk/app/views/users/signin.rhtml
r986 r1182 6 6 <%= password_field("user", "password") %></p> 7 7 <%= submit_tag "Se connecter" %> 8 ou 9 <%= link_to "rappel de votre mot de passe ›", :controller => :users, :action => :recover_password, :class => "blue" %> 8 10 <% end %> 11 9 12 <% form_tag(:action => :begin) do %> 10 13 <p><label for="openid_url">OpenId :</label><br/>
