phoenix_auth 0.2.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -0
- data/app/assets/stylesheets/user.css +0 -0
- data/app/controllers/phoenix/base_controller_decorator.rb +8 -0
- data/app/controllers/phoenix/confirmations_controller.rb +16 -0
- data/app/controllers/phoenix/passwords_controller.rb +16 -0
- data/app/controllers/phoenix/profiles_controller.rb +17 -0
- data/app/controllers/phoenix/registrations_controller.rb +52 -0
- data/app/controllers/phoenix/sessions_controller.rb +35 -0
- data/app/controllers/phoenix/users_controller.rb +32 -0
- data/app/helpers/phoenix/users_helper.rb +4 -0
- data/app/mailers/phoenix/user_mailer.rb +30 -0
- data/app/models/phoenix/profile.rb +10 -0
- data/app/models/phoenix/user.rb +69 -0
- data/app/models/phoenix/user_observer.rb +7 -0
- data/app/views/phoenix/confirmations/new.html.haml +16 -0
- data/app/views/phoenix/layouts/login.html.erb +24 -0
- data/app/views/phoenix/layouts/login.html.haml +19 -0
- data/app/views/phoenix/layouts/mailer.html.haml +7 -0
- data/app/views/phoenix/passwords/edit.html.haml +21 -0
- data/app/views/phoenix/passwords/new.html.haml +13 -0
- data/app/views/phoenix/profiles/index.html.haml +2 -0
- data/app/views/phoenix/registrations/edit.html.haml +5 -0
- data/app/views/phoenix/registrations/new.html.erb +12 -0
- data/app/views/phoenix/registrations/new.html.haml +14 -0
- data/app/views/phoenix/sessions/authorization_failure.html.haml +23 -0
- data/app/views/phoenix/sessions/new.html.erb +41 -0
- data/app/views/phoenix/sessions/new.html.haml +27 -0
- data/app/views/phoenix/user_mailer/confirmation_instructions.html.haml +8 -0
- data/app/views/phoenix/user_mailer/reset_password_instructions.html.haml +16 -0
- data/app/views/phoenix/user_mailer/welcome_instructions.html.haml +2 -0
- data/app/views/phoenix/users/edit.html.haml +1 -0
- data/app/views/phoenix/users/index.html.haml +12 -0
- data/app/views/phoenix/users/profile.html.erb +8 -0
- data/app/views/phoenix/users/profile.html.haml +7 -0
- data/app/views/phoenix/users/show.html.haml +12 -0
- data/config/initializers/custom_devise_failure.rb +8 -0
- data/config/initializers/devise.rb +136 -0
- data/config/locales/devise/en.yml +51 -0
- data/config/locales/devise/zh-CN.yml +120 -0
- data/config/locales/devise/zh-TW.yml +119 -0
- data/config/routes.rb +21 -0
- data/lib/phoenix/auth.rb +10 -0
- data/lib/phoenix/auth/engine.rb +33 -0
- data/lib/phoenix/token_resource.rb +17 -0
- data/lib/phoenix_auth.rb +1 -0
- data/lib/tasks/phoenix_auth_tasks.rake +4 -0
- metadata +113 -0
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Phoenix
|
2
|
+
class RegistrationsController < Devise::RegistrationsController
|
3
|
+
include Phoenix::Core::ControllerHelpers
|
4
|
+
|
5
|
+
#before_filter :check_registrations_open!
|
6
|
+
#ssl_required
|
7
|
+
|
8
|
+
layout "/phoenix/layouts/login"
|
9
|
+
|
10
|
+
def new
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@user = build_resource(params[:user])
|
16
|
+
|
17
|
+
if resource.save
|
18
|
+
set_flash_message(:notice, :signed_up)
|
19
|
+
fire_event('phoeinx.user.signup', :user => @user)
|
20
|
+
#sign_in_and_redirect(:user, @user)
|
21
|
+
redirect_to phoenix.root_path
|
22
|
+
else
|
23
|
+
clean_up_passwords(resource)
|
24
|
+
render_with_scope(:new)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# GET /resource/edit
|
29
|
+
def edit
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
# PUT /resource
|
34
|
+
def update
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
# DELETE /resource
|
39
|
+
def destroy
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
private
|
45
|
+
def check_registrations_open!
|
46
|
+
if AppConfig[:registrations_closed]
|
47
|
+
flash[:error] = 'registrations.closed'
|
48
|
+
redirect_to new_user_session_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Phoenix
|
2
|
+
class SessionsController < Devise::SessionsController
|
3
|
+
include Phoenix::Core::ControllerHelpers
|
4
|
+
|
5
|
+
layout "/phoenix/layouts/login"
|
6
|
+
|
7
|
+
# GET /resource/sign_in
|
8
|
+
def new
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
# POST /resource/sign_in
|
13
|
+
def create
|
14
|
+
authenticate_user!
|
15
|
+
|
16
|
+
if user_signed_in?
|
17
|
+
respond_to do |format|
|
18
|
+
format.html {
|
19
|
+
flash.notice = "logged_in_succesfully111"
|
20
|
+
redirect_to phoenix.login_path
|
21
|
+
}
|
22
|
+
end
|
23
|
+
else
|
24
|
+
flash[:error] = 'devise.failure.invalid'
|
25
|
+
render :new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# GET /resource/sign_out
|
30
|
+
def destroy
|
31
|
+
session.clear
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Phoenix
|
2
|
+
class UsersController < Phoenix::BaseController
|
3
|
+
before_filter :authenticate_user!, :except => [:index]
|
4
|
+
|
5
|
+
def index
|
6
|
+
@users = User.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def edit
|
10
|
+
@user = current_user
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
#redirect_to(root_path)
|
15
|
+
@user = User.find_by_slug(params[:id])
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
@user = User.find_by_slug(params[:id])
|
20
|
+
|
21
|
+
respond_to do |format|
|
22
|
+
if @user.update_attributes(params[:user])
|
23
|
+
format.html { redirect_to(users_path, :notice => 'User Update Successful') }
|
24
|
+
format.json
|
25
|
+
else
|
26
|
+
format.html { render :action => "edit" }
|
27
|
+
format.json
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Phoenix
|
2
|
+
class UserMailer < Phoenix::BaseMailer
|
3
|
+
layout "/phoenix/layouts/mailer"
|
4
|
+
|
5
|
+
default :from => "Phoenix Engine <phoenix@lanvige.com>"
|
6
|
+
|
7
|
+
def confirmation_instructions(user)
|
8
|
+
@user = user
|
9
|
+
mail(:to => "#{user.name} <#{user.email}>",
|
10
|
+
:subject => I18n.t('devise.mailer.confirmation_instructions.subject'))
|
11
|
+
end
|
12
|
+
|
13
|
+
# UserMailer.welcome_instructions(@user).deliver
|
14
|
+
def welcome_instructions(user)
|
15
|
+
@user = user
|
16
|
+
mail(:to => "#{user.name} <#{user.email}>",
|
17
|
+
:subject => I18n.t('devise.mailer.welcome_instructions.subject'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_password_instructions(user)
|
21
|
+
@user = user
|
22
|
+
mail(:to => "#{user.name} <#{user.email}>",
|
23
|
+
:subject => I18n.t('devise.mailer.reset_password_instructions.subject'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def unlock_instructions(user)
|
27
|
+
#devise_mail(user, :unlock_instructions)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Phoenix
|
2
|
+
class User
|
3
|
+
include Mongoid::Document
|
4
|
+
include Mongoid::Timestamps
|
5
|
+
include Mongoid::Slug
|
6
|
+
|
7
|
+
embeds_one :profile
|
8
|
+
|
9
|
+
# Set the collection name in MongoDB
|
10
|
+
self.collection_name = 'users'
|
11
|
+
|
12
|
+
# Include default devise modules. Others available are:
|
13
|
+
devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable,
|
14
|
+
:rememberable, :trackable, :validatable, :timeoutable, :confirmable,
|
15
|
+
:encryptable, :encryptor => 'authlogic_sha512'
|
16
|
+
|
17
|
+
field :name
|
18
|
+
field :email
|
19
|
+
field :avatar
|
20
|
+
field :bio
|
21
|
+
field :website
|
22
|
+
|
23
|
+
# define the slug for mongoid_slug
|
24
|
+
slug :name
|
25
|
+
|
26
|
+
validates_presence_of :name
|
27
|
+
validates_format_of :name, :with => /\A[A-Za-z0-9_]+\z/
|
28
|
+
validates_length_of :name, :maximum => 32
|
29
|
+
validates_uniqueness_of :name, :email, :case_sensitive => false
|
30
|
+
|
31
|
+
attr_accessor :password_confirmation
|
32
|
+
|
33
|
+
# Setup accessible (or protected) attributes for user model
|
34
|
+
attr_accessible :name, :email, :password, :avatar, :password_confirmation, :remember_me
|
35
|
+
|
36
|
+
# devise confirm! method overriden
|
37
|
+
# Send a welcome mail when user confirmed registe with mail.
|
38
|
+
def confirm!
|
39
|
+
super
|
40
|
+
welcome_instructions
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def self.current
|
45
|
+
Thread.current[:user]
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.current=(user)
|
49
|
+
Thread.current[:user] = user
|
50
|
+
end
|
51
|
+
|
52
|
+
def welcome_instructions
|
53
|
+
UserMailer.welcome_instructions(self).deliver
|
54
|
+
end
|
55
|
+
|
56
|
+
# Generate a friendly string randomically to be used as token.
|
57
|
+
def self.friendly_token
|
58
|
+
SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
# Generate a token by looping and ensuring does not already exist.
|
62
|
+
def self.generate_token(column)
|
63
|
+
loop do
|
64
|
+
token = friendly_token
|
65
|
+
break token unless find(:first, :conditions => { column => token })
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
%h2
|
2
|
+
Resend confirmation instructions
|
3
|
+
|
4
|
+
= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f|
|
5
|
+
= devise_error_messages!
|
6
|
+
|
7
|
+
%div
|
8
|
+
= f.label :email
|
9
|
+
%br
|
10
|
+
= f.email_field :email
|
11
|
+
|
12
|
+
%div
|
13
|
+
= f.submit "Resend confirmation instructions"
|
14
|
+
|
15
|
+
%br
|
16
|
+
= render :partial => "devise/shared/links"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<!DOCTYPE HTML>
|
2
|
+
<html lang="en-US">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>Auth</title>
|
6
|
+
<%= stylesheet_link_tag "application" %>
|
7
|
+
<%= javascript_include_tag "application" %>
|
8
|
+
<%= csrf_meta_tags %>
|
9
|
+
<!--[if lt IE 9]>
|
10
|
+
<%= javascript_include_tag "html5" %>
|
11
|
+
<![endif]-->
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<header>
|
15
|
+
|
16
|
+
</header>
|
17
|
+
<div id="body">
|
18
|
+
<%= yield %>
|
19
|
+
</div>
|
20
|
+
<footer>
|
21
|
+
|
22
|
+
</footer>
|
23
|
+
</body>
|
24
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{:charset => 'utf-8'}
|
5
|
+
|
6
|
+
%title Login Page
|
7
|
+
|
8
|
+
%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
|
9
|
+
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}
|
10
|
+
|
11
|
+
= csrf_meta_tag
|
12
|
+
= javascript_include_tag 'application'
|
13
|
+
= stylesheet_link_tag :application
|
14
|
+
|
15
|
+
%body{:class => "body"}
|
16
|
+
= yield
|
17
|
+
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
%h2
|
2
|
+
Change your password
|
3
|
+
|
4
|
+
= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f|
|
5
|
+
= devise_error_messages!
|
6
|
+
= f.hidden_field :reset_password_token
|
7
|
+
|
8
|
+
%div
|
9
|
+
= f.label :password, "New password"
|
10
|
+
%br
|
11
|
+
= f.password_field :password
|
12
|
+
|
13
|
+
%div
|
14
|
+
= f.label :password_confirmation, "Confirm new password"
|
15
|
+
%br
|
16
|
+
= f.password_field :password_confirmation
|
17
|
+
|
18
|
+
%div
|
19
|
+
= f.submit "Change my password"
|
20
|
+
|
21
|
+
= render :partial => "devise/shared/links"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%h3
|
2
|
+
= 'forgot password'
|
3
|
+
|
4
|
+
= form_for(resource, :as => resource_name, :url => password_path(resource_name)) do |f|
|
5
|
+
= devise_error_messages!
|
6
|
+
|
7
|
+
%p
|
8
|
+
= f.label :email
|
9
|
+
= f.text_field :email
|
10
|
+
%p
|
11
|
+
|
12
|
+
= f.submit 'send_password_instructions'
|
13
|
+
= render :partial => "devise/shared/links"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div id="signup-form">
|
2
|
+
<h3>Sign Up</h3>
|
3
|
+
<%= simple_form_for( resource, :as => resource_name, :url => registration_path(resource_name) ) do |f| %>
|
4
|
+
<%= devise_error_messages!%>
|
5
|
+
<p><%= f.input :name%></p>
|
6
|
+
<p><%= f.input :email%></p>
|
7
|
+
<p><%= f.input :password%></p>
|
8
|
+
<p><%= f.input :password_confirmation%></p>
|
9
|
+
<p><%= f.button :submit%></p>
|
10
|
+
<p>end of form</p>
|
11
|
+
<% end %>
|
12
|
+
</div>
|