Omniauth Support
This commit is contained in:
parent
4ce034ca65
commit
a64aff2f1c
20 changed files with 195 additions and 61 deletions
10
app/assets/stylesheets/auth_methods.scss
Normal file
10
app/assets/stylesheets/auth_methods.scss
Normal file
|
@ -0,0 +1,10 @@
|
|||
.auth_methods {
|
||||
&ul {
|
||||
margin: 0;
|
||||
text-align:center;
|
||||
padding: 5px;
|
||||
&li {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
/** GITLAB colors **/
|
||||
$text_color:#222;
|
||||
$lite_text_color: #666;
|
||||
$link_color:#2A79A3;
|
||||
$lite_text_color: #666;
|
||||
$link_color:#2A79A3;
|
||||
$active_link_color:#2FA0BB;
|
||||
$active_bg_color:#79C3E0;
|
||||
$active_bd_color: #2FA0BB;
|
||||
|
@ -31,7 +31,7 @@ $hover: #FDF5D9;
|
|||
box-shadow: 0 0 3px #ddd;
|
||||
}
|
||||
|
||||
@mixin solid_shade {
|
||||
@mixin solid_shade {
|
||||
-moz-box-shadow: 0 0 0 3px #eee;
|
||||
-webkit-box-shadow: 0 0 0 3px #eee;
|
||||
box-shadow: 0 0 0 3px #eee;
|
||||
|
@ -73,21 +73,21 @@ $hover: #FDF5D9;
|
|||
|
||||
|
||||
/**
|
||||
* Header of application.
|
||||
* Header of application.
|
||||
* Contain application logo, search panel, profile icon
|
||||
*/
|
||||
@import "sections/header.scss";
|
||||
|
||||
/**
|
||||
* Navigation menu of application.
|
||||
* Navigation menu of application.
|
||||
* Panel with links to pages depends on project, profile or admin area
|
||||
*/
|
||||
@import "sections/nav.scss";
|
||||
|
||||
/**
|
||||
* This file represent some UI that can be changed
|
||||
* during web app restyle or theme select.
|
||||
*
|
||||
* This file represent some UI that can be changed
|
||||
* during web app restyle or theme select.
|
||||
*
|
||||
* Next items should be placed there
|
||||
* - link, button colors
|
||||
* - header restyles
|
||||
|
@ -118,11 +118,11 @@ $hover: #FDF5D9;
|
|||
* Most of application styles placed here.
|
||||
* This file represent common UI that should not be changed between themes
|
||||
* or project restyling like form width or user avatar class or commit title
|
||||
*
|
||||
*
|
||||
* TODO: clean it
|
||||
*/
|
||||
@import "common.scss";
|
||||
|
||||
@import "auth_methods.scss";
|
||||
|
||||
/**
|
||||
* Styles related to specific part of app
|
||||
|
@ -140,17 +140,17 @@ $hover: #FDF5D9;
|
|||
@import "ref_select.scss";
|
||||
|
||||
/**
|
||||
* Code (files list) styles. Browsing project files there
|
||||
* Code (files list) styles. Browsing project files there
|
||||
*/
|
||||
@import "sections/tree.scss";
|
||||
|
||||
/**
|
||||
* This file represent notes(comments) styles
|
||||
* This file represent notes(comments) styles
|
||||
*/
|
||||
@import "sections/notes.scss";
|
||||
|
||||
/**
|
||||
* Devise styles
|
||||
* Devise styles
|
||||
*/
|
||||
@import "sections/login.scss";
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||
error ||= env["omniauth.error.type"].to_s
|
||||
error.to_s.humanize if error
|
||||
end
|
||||
|
||||
|
||||
def ldap
|
||||
# We only find ourselves here if the authentication to LDAP was successful.
|
||||
info = request.env["omniauth.auth"]["info"]
|
||||
|
@ -20,4 +20,34 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||
sign_in_and_redirect @user
|
||||
end
|
||||
|
||||
Settings.omniauth_providers.each do |provider|
|
||||
define_method provider['name'] do
|
||||
handle_omniauth
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def handle_omniauth
|
||||
oauth = request.env['omniauth.auth']
|
||||
provider, uid = oauth['provider'], oauth['uid']
|
||||
|
||||
if current_user
|
||||
# Change a logged-in user's authentication method:
|
||||
current_user.uid = uid
|
||||
current_user.provider = provider
|
||||
current_user.save
|
||||
redirect_to profile_path
|
||||
else
|
||||
@user = User.find_by_provider_and_uid(provider, uid)
|
||||
|
||||
if @user
|
||||
sign_in_and_redirect @user
|
||||
else
|
||||
flash[:notice] = "There's no such user!"
|
||||
redirect_to new_user_session_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -75,16 +75,16 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def show_last_push_widget?(event)
|
||||
event &&
|
||||
event &&
|
||||
event.last_push_to_non_root? &&
|
||||
!event.rm_ref? &&
|
||||
event.project &&
|
||||
event.project &&
|
||||
event.project.merge_requests_enabled
|
||||
end
|
||||
|
||||
def tab_class(tab_key)
|
||||
active = case tab_key
|
||||
|
||||
|
||||
# Project Area
|
||||
when :wall; wall_tab?
|
||||
when :wiki; controller.controller_name == "wikis"
|
||||
|
@ -123,4 +123,9 @@ module ApplicationHelper
|
|||
def hexdigest(string)
|
||||
Digest::SHA1.hexdigest string
|
||||
end
|
||||
|
||||
def authbutton(provider, size = 64)
|
||||
image_tag("authbuttons/#{provider.to_s.split('_').first}_#{size}.png",
|
||||
alt: "Sign in with #{provider.to_s.titleize}" )
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,10 +14,15 @@
|
|||
<div class="right"> <%= render :partial => "devise/shared/links" %></div>
|
||||
|
||||
<%- if devise_mapping.omniauthable? %>
|
||||
<%- resource_class.omniauth_providers.each do |provider| %>
|
||||
<hr/>
|
||||
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider), :class => "btn primary" %><br />
|
||||
<% end -%>
|
||||
<hr/>
|
||||
<div class="auth_methods">
|
||||
<ul>
|
||||
<%- resource_class.omniauth_providers.each do |provider| %>
|
||||
<li><%= link_to authbutton(provider),
|
||||
omniauth_authorize_path(resource_name, provider) %></li>
|
||||
<% end -%>
|
||||
</ul>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
<% end %>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
= link_to "Profile", profile_path
|
||||
|
||||
%li{class: tab_class(:password)}
|
||||
= link_to "Password", profile_password_path
|
||||
= link_to "Authentication", profile_password_path
|
||||
|
||||
%li{class: tab_class(:ssh_keys)}
|
||||
= link_to keys_path do
|
||||
|
|
|
@ -1,19 +1,31 @@
|
|||
%h3.page_title Password
|
||||
%hr
|
||||
= form_for @user, url: profile_password_path, method: :put do |f|
|
||||
.data
|
||||
%p.slead After successful password update you will be redirected to login page where you should login with new password
|
||||
-if @user.errors.any?
|
||||
.alert-message.block-message.error
|
||||
%ul
|
||||
- @user.errors.full_messages.each do |msg|
|
||||
%li= msg
|
||||
|
||||
.clearfix
|
||||
= f.label :password
|
||||
.input= f.password_field :password
|
||||
.clearfix
|
||||
= f.label :password_confirmation
|
||||
.input= f.password_field :password_confirmation
|
||||
= form_for @user, url: profile_password_path, method: :put do |f|
|
||||
.row
|
||||
.span7
|
||||
.data
|
||||
%p.slead After successful password update you will be redirected to login page where you should login with new password
|
||||
-if @user.errors.any?
|
||||
.alert-message.block-message.error
|
||||
%ul
|
||||
- @user.errors.full_messages.each do |msg|
|
||||
%li= msg
|
||||
|
||||
.clearfix
|
||||
= f.label :password
|
||||
.input= f.password_field :password
|
||||
.clearfix
|
||||
= f.label :password_confirmation
|
||||
.input= f.password_field :password_confirmation
|
||||
|
||||
- if Settings.omniauth.enabled
|
||||
.span5.right
|
||||
.auth_methods.alert.alert-info
|
||||
%strong Tip: Use one of the following sites to login
|
||||
%ul
|
||||
- User.omniauth_providers.each do |provider|
|
||||
%li= link_to authbutton(provider), |
|
||||
omniauth_authorize_path(User, provider) |
|
||||
.actions
|
||||
= f.submit 'Save', class: "btn primary"
|
||||
|
|
|
@ -49,6 +49,13 @@
|
|||
%strong Tip:
|
||||
You can change your avatar at gravatar.com
|
||||
|
||||
- if Settings.omniauth.enabled && @user.provider?
|
||||
%h4
|
||||
Omniauth Providers:
|
||||
= link_to "Change", profile_password_path, class: "btn small right"
|
||||
You can login through #{@user.provider.titleize}!
|
||||
= authbutton(@user.provider, 32)
|
||||
|
||||
%h4
|
||||
Personal projects:
|
||||
%small.right
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue