| 
				
			 | 
			
			
				@@ -11,11 +11,14 @@ class AuthenticationController < ApplicationController 
			 | 
		
	
		
			
			| 
				11
			 | 
			
				11
			 | 
			
			
				     else 
			 | 
		
	
		
			
			| 
				12
			 | 
			
				12
			 | 
			
			
				       u = User.find_by(email: params[:session][:email]) 
			 | 
		
	
		
			
			| 
				13
			 | 
			
				13
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				14
			 | 
			
				
			 | 
			
			
				-      if u && u.authenticate(params[:session][:password]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+      if u && u.confirmed && u.authenticate(params[:session][:password]) 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				15
			 | 
			
			
				         log_in(u, params[:session][:remember_me].to_i) 
			 | 
		
	
		
			
			| 
				16
			 | 
			
				16
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				17
			 | 
			
				17
			 | 
			
			
				         flash[:success] = "Hello, #{u.person.full_name}!" 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				18
			 | 
			
			
				         redirect_to root_path 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+      elsif u and not u.confirmed 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+        flash[:warning] = "Your account has not been activated yet, please confirm using the email you have received." 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+        redirect_to action: 'login_form' 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				22
			 | 
			
			
				       else 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				23
			 | 
			
			
				         flash[:danger] = "Invalid username/password combination!" 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				24
			 | 
			
			
				         redirect_to action: 'login_form' 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -41,7 +44,32 @@ class AuthenticationController < ApplicationController 
			 | 
		
	
		
			
			| 
				41
			 | 
			
				44
			 | 
			
			
				   end 
			 | 
		
	
		
			
			| 
				42
			 | 
			
				45
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				43
			 | 
			
				46
			 | 
			
			
				   def create_password 
			 | 
		
	
		
			
			| 
				44
			 | 
			
				
			 | 
			
			
				-    flash[:danger] = "Not yet implemented." 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+    person = Person.find_by(email: params[:user][:email]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+    if not person 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+      flash[:warning] = "That email address is unknown!" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+      redirect_to action: 'create_password_form' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+      return 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+    end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+    user = User.find_by(person: person) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+    if user and user.confirmed 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+      flash[:warning] = "Your account has already been activated, please use the login form if you have forgotten your password." 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+      redirect_to action: 'login' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+      return 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+    end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+    if not user 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+      user = User.new 
			 | 
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				+      user.person = person 
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+      user.email = person.email 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+      user.password = user.password_confirmation = SecureRandom::urlsafe_base64 32 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+      user.confirmed = false 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+      user.save! 
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+    end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+    AuthenticationMailer::password_confirm_email(user).deliver_now 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+    flash[:success] = "An email has been sent, check your inbox!" 
			 | 
		
	
		
			
			| 
				45
			 | 
			
				73
			 | 
			
			
				     redirect_to action: 'login' 
			 | 
		
	
		
			
			| 
				46
			 | 
			
				74
			 | 
			
			
				   end 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				75
			 | 
			
			
				  
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -63,7 +91,7 @@ class AuthenticationController < ApplicationController 
			 | 
		
	
		
			
			| 
				63
			 | 
			
				91
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				64
			 | 
			
				92
			 | 
			
			
				   def reset_password_form 
			 | 
		
	
		
			
			| 
				65
			 | 
			
				93
			 | 
			
			
				     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset]) 
			 | 
		
	
		
			
			| 
				66
			 | 
			
				
			 | 
			
			
				-    if not password_reset_token_valid? token 
			 | 
		
	
		
			
			| 
				
			 | 
			
				94
			 | 
			
			
				+    if not token_valid? token 
			 | 
		
	
		
			
			| 
				67
			 | 
			
				95
			 | 
			
			
				       return 
			 | 
		
	
		
			
			| 
				68
			 | 
			
				96
			 | 
			
			
				     end 
			 | 
		
	
		
			
			| 
				69
			 | 
			
				97
			 | 
			
			
				     render layout: 'void' 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -71,7 +99,7 @@ class AuthenticationController < ApplicationController 
			 | 
		
	
		
			
			| 
				71
			 | 
			
				99
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				72
			 | 
			
				100
			 | 
			
			
				   def reset_password 
			 | 
		
	
		
			
			| 
				73
			 | 
			
				101
			 | 
			
			
				     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset]) 
			 | 
		
	
		
			
			| 
				74
			 | 
			
				
			 | 
			
			
				-    if not password_reset_token_valid? token 
			 | 
		
	
		
			
			| 
				
			 | 
			
				102
			 | 
			
			
				+    if not token_valid? token 
			 | 
		
	
		
			
			| 
				75
			 | 
			
				103
			 | 
			
			
				       return 
			 | 
		
	
		
			
			| 
				76
			 | 
			
				104
			 | 
			
			
				     end 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				105
			 | 
			
			
				  
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -92,12 +120,36 @@ class AuthenticationController < ApplicationController 
			 | 
		
	
		
			
			| 
				92
			 | 
			
				120
			 | 
			
			
				     redirect_to action: 'login' 
			 | 
		
	
		
			
			| 
				93
			 | 
			
				121
			 | 
			
			
				   end 
			 | 
		
	
		
			
			| 
				94
			 | 
			
				122
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				123
			 | 
			
			
				+  def confirm_account_form 
			 | 
		
	
		
			
			| 
				
			 | 
			
				124
			 | 
			
			
				+    token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:account_confirmation]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				125
			 | 
			
			
				+    return unless token_valid? token 
			 | 
		
	
		
			
			| 
				
			 | 
			
				126
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				127
			 | 
			
			
				+    @user = token.user 
			 | 
		
	
		
			
			| 
				
			 | 
			
				128
			 | 
			
			
				+    render layout: 'void' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				129
			 | 
			
			
				+  end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				130
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				131
			 | 
			
			
				+  def confirm_account 
			 | 
		
	
		
			
			| 
				
			 | 
			
				132
			 | 
			
			
				+    token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:account_confirmation]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				133
			 | 
			
			
				+    return unless token_valid? token 
			 | 
		
	
		
			
			| 
				
			 | 
			
				134
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				135
			 | 
			
			
				+    user = token.user 
			 | 
		
	
		
			
			| 
				
			 | 
			
				136
			 | 
			
			
				+    user.password = params[:account_confirmation][:password] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				137
			 | 
			
			
				+    user.password_confirmation = params[:account_confirmation][:password_confirmation] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				138
			 | 
			
			
				+    user.confirmed = true 
			 | 
		
	
		
			
			| 
				
			 | 
			
				139
			 | 
			
			
				+    user.save! 
			 | 
		
	
		
			
			| 
				
			 | 
			
				140
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				141
			 | 
			
			
				+    token.destroy! 
			 | 
		
	
		
			
			| 
				
			 | 
			
				142
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				143
			 | 
			
			
				+    flash[:success] = "Your account has been confirmed, you may now log in." 
			 | 
		
	
		
			
			| 
				
			 | 
			
				144
			 | 
			
			
				+    redirect_to action: 'login' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				145
			 | 
			
			
				+  end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				146
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				95
			 | 
			
				147
			 | 
			
			
				   private 
			 | 
		
	
		
			
			| 
				96
			 | 
			
				148
			 | 
			
			
				   def session_params 
			 | 
		
	
		
			
			| 
				97
			 | 
			
				149
			 | 
			
			
				     params.require(:session).permit(:email, :password, :remember_me) 
			 | 
		
	
		
			
			| 
				98
			 | 
			
				150
			 | 
			
			
				   end 
			 | 
		
	
		
			
			| 
				99
			 | 
			
				151
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				100
			 | 
			
				
			 | 
			
			
				-  def password_reset_token_valid?(token) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				152
			 | 
			
			
				+  def token_valid?(token) 
			 | 
		
	
		
			
			| 
				101
			 | 
			
				153
			 | 
			
			
				     if token.nil? 
			 | 
		
	
		
			
			| 
				102
			 | 
			
				154
			 | 
			
			
				       flash[:warning] = "No valid token specified!" 
			 | 
		
	
		
			
			| 
				103
			 | 
			
				155
			 | 
			
			
				       redirect_to action: 'login' 
			 |