-
Notifications
You must be signed in to change notification settings - Fork 14
Feature/coach login with GitHub & admin login with username/password #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dbc148b
79445f8
089e1eb
703b0be
cc649b2
ac82d6f
982f2a3
a3ada8b
acad466
e594d45
65dee30
aeb22e1
a59f53d
210605a
7abeb4d
d78f7b1
b94d7fd
d71c2da
5c127d4
fa7c364
3d0caf7
bab3832
a70594d
1a1b511
f99a57d
d9eba9a
8e3e1bd
327480a
f9959ab
76378af
c47f8dd
3a2ce5e
10790f9
687b040
e720fd9
800848a
031c182
edcaff0
4c274c5
fbbe572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
| # You should configure your model like this: | ||
| # devise :omniauthable, omniauth_providers: [:twitter] | ||
|
|
||
| # You should also create an action method in this controller like this: | ||
| # def twitter | ||
| # end | ||
|
|
||
| # More info at: | ||
| # https://github.com/plataformatec/devise#omniauth | ||
|
|
||
| # GET|POST /resource/auth/twitter | ||
| # def passthru | ||
| # super | ||
| # end | ||
|
|
||
| # GET|POST /users/auth/twitter/callback | ||
| # def failure | ||
| # super | ||
| # end | ||
|
|
||
| # protected | ||
|
|
||
| # The path used when OmniAuth fails | ||
| # def after_omniauth_failure_path_for(scope) | ||
| # super(scope) | ||
| # end | ||
|
|
||
| def github | ||
| @user = User.from_omniauth(request.env["omniauth.auth"]) | ||
| if @user.nil? | ||
| flash[:alert] = "You are not authorized." | ||
| redirect_to new_user_session_path | ||
| else | ||
| flash[:notice] = "Signed in successfully." | ||
| sign_in_and_redirect @user | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # == Schema Information | ||
| # | ||
| # Table name: users | ||
| # | ||
| # id :integer not null, primary key | ||
| # email :string default(""), not null | ||
| # encrypted_password :string default(""), not null | ||
| # reset_password_token :string | ||
| # reset_password_sent_at :datetime | ||
| # remember_created_at :datetime | ||
| # sign_in_count :integer default(0), not null | ||
| # current_sign_in_at :datetime | ||
| # last_sign_in_at :datetime | ||
| # current_sign_in_ip :string | ||
| # last_sign_in_ip :string | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # provider :string | ||
| # uid :string | ||
| # role :string default("coach"), not null | ||
| # | ||
|
|
||
| class User < ActiveRecord::Base | ||
| # Include default devise modules. Others available are: | ||
| # :confirmable, :lockable, :timeoutable and :omniauthable | ||
| devise :database_authenticatable, :recoverable, | ||
| :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:github] | ||
|
|
||
| ADMIN = "admin" | ||
| COACH = "coach" | ||
|
|
||
| def self.from_omniauth(auth) | ||
| email = auth.info.email.nil? ? auth.extra.raw_info.email : auth.info.email | ||
| login = auth.extra.raw_info.login | ||
| if !login.nil? and !email.nil? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this block of code is ripe for pulling out as a separate method - we could also rewrite as ah, I guess the method is not so huge because it's just block syntax on that first_or_create, but we could extract that as a separate method and self document like so: unless login.nil or email.nil? just some thoughts ... |
||
| User.where(provider: auth.provider, provider_username: login, email: email).first_or_create do |user| | ||
| user.provider = auth.provider | ||
| user.uid = auth.uid | ||
| user.email = email | ||
| user.provider_username = login | ||
| user.password = Devise.friendly_token[0,20] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def is_admin? | ||
| self.role == ADMIN | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <h2>Resend confirmation instructions</h2> | ||
|
|
||
| <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> | ||
| <%= devise_error_messages! %> | ||
|
|
||
| <div class="field"> | ||
| <%= f.label :email %><br /> | ||
| <%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> | ||
| </div> | ||
|
|
||
| <div class="actions"> | ||
| <%= f.submit "Resend confirmation instructions" %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <%= render "devise/shared/links" %> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <p>Welcome <%= @email %>!</p> | ||
|
|
||
| <p>You can confirm your account email through the link below:</p> | ||
|
|
||
| <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <p>Hello <%= @resource.email %>!</p> | ||
|
|
||
| <p>We're contacting you to notify you that your password has been changed.</p> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <p>Hello <%= @resource.email %>!</p> | ||
|
|
||
| <p>Someone has requested a link to change your password. You can do this through the link below.</p> | ||
|
|
||
| <p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p> | ||
|
|
||
| <p>If you didn't request this, please ignore this email.</p> | ||
| <p>Your password won't change until you access the link above and create a new one.</p> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <p>Hello <%= @resource.email %>!</p> | ||
|
|
||
| <p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p> | ||
|
|
||
| <p>Click the link below to unlock your account:</p> | ||
|
|
||
| <p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method is a bit long - I'll still pull in but it would be good to refactor to make it easier to see what the components are doing