Merge branch 'persona-integration' of git://github.com/callahad/discourse

This commit is contained in:
Robin Ward 2013-03-04 11:51:26 -05:00
commit f7c9efb101
13 changed files with 108 additions and 1 deletions

View File

@ -36,6 +36,7 @@ gem "openid-redis-store"
gem "omniauth-facebook"
gem "omniauth-twitter"
gem "omniauth-github"
gem "omniauth-browserid", :git => "git://github.com/callahad/omniauth-browserid.git", :branch => "observer_api"
gem 'oj'
gem 'pbkdf2'
gem 'pg'

View File

@ -5,6 +5,16 @@ GIT
rack-mini-profiler (0.1.23)
rack (>= 1.1.3)
GIT
remote: git://github.com/callahad/omniauth-browserid.git
revision: af62d667626c1622de6fe13b60849c3640765ab1
branch: observer_api
specs:
omniauth-browserid (0.0.2)
faraday
multi_json
omniauth (~> 1.0)
GIT
remote: git://github.com/emberjs/ember-rails.git
revision: 57bbe3202725e55a8e4eaccba83d663b26bcf024
@ -490,6 +500,7 @@ DEPENDENCIES
nokogiri
oj
omniauth
omniauth-browserid!
omniauth-facebook
omniauth-github
omniauth-openid

View File

@ -16,6 +16,10 @@
{{#if Discourse.SiteSettings.enable_github_logins}}
<button class="btn btn-social github" title="{{i18n login.github.title}}" {{action "githubLogin" target="view"}}>{{i18n login.github.title}}</button>
{{/if}}
{{#if Discourse.SiteSettings.enable_persona_logins}}
<br>
<button class="btn btn-social persona" title="{{i18n login.persona.title}}" {{action "personaLogin" target="view"}}>{{i18n login.persona.title}}</button>
{{/if}}
</div>
<h3 style="text-align:center; margin-bottom:10px;">
{{i18n login.or}}

View File

@ -109,6 +109,10 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
return window.open("/auth/github", "_blank", "menubar=no,status=no,height=400,width=800,left=" + left + ",top=" + top);
},
personaLogin: function() {
navigator.id.request();
},
authenticationComplete: function(options) {
if (options.awaiting_approval) {
this.flash(Em.String.i18n('login.awaiting_approval'), 'success');

View File

@ -168,6 +168,12 @@
content: "g";
}
}
&.persona {
background: $persona;
&:before {
content: "]";
}
}
}
// Button Sizes

View File

@ -124,6 +124,7 @@ $facebook: #3b5998 !default;
$twitter: #00bced !default;
$yahoo: #810293 !default;
$github: #6d6d6d !default;
$persona: #606060 !default;
// Layout dimensions
@ -174,4 +175,4 @@ $heart: #fa6c8d;
$attention_bg: #e4f2f8;
$attention_fg: #1aaae4;
$header-item-highlight: #ecf8f6;
$header-item-highlight: #ecf8f6;

View File

@ -21,6 +21,13 @@ class Users::OmniauthCallbacksController < ApplicationController
create_or_sign_on_user_using_openid(auth_token)
when "github"
create_or_sign_on_user_using_github(auth_token)
when "persona"
create_or_sign_on_user_using_persona(auth_token)
end
respond_to do |format|
format.html
format.json { render :json => @data }
end
end
@ -169,6 +176,7 @@ class Users::OmniauthCallbacksController < ApplicationController
openid_url: identity_url
}
end
end
def create_or_sign_on_user_using_github(auth_token)
@ -200,6 +208,37 @@ class Users::OmniauthCallbacksController < ApplicationController
else
@data[:name] = screen_name
end
end
def create_or_sign_on_user_using_persona(auth_token)
email = auth_token[:info][:email]
user = User.find_by_email(email)
if user
if SiteSetting.must_approve_users? and !user.approved?
@data = {awaiting_approval: true}
else
log_on_user(user)
@data = {authenticated: true}
end
else
@data = {
email: email,
email_valid: true,
name: User.suggest_name(email),
username: User.suggest_username(email),
auth_provider: params[:provider].try(:capitalize)
}
session[:authentication] = {
email: email,
email_valid: true,
}
end
end
end

View File

@ -122,6 +122,8 @@ class SiteSetting < ActiveRecord::Base
setting(:github_client_id, '')
setting(:github_client_secret, '')
client_setting(:enable_persona_logins, true)
setting(:enforce_global_nicknames, true)
setting(:discourse_org_access_key, '')
setting(:enable_s3_uploads, false)

View File

@ -0,0 +1,30 @@
<script src="https://login.persona.org/include.js"></script>
<script>
(function() {
var readyCalled = false;
navigator.id.watch({
onlogin: function(assertion) {
if (readyCalled) {
$.ajax({
type: 'POST',
url: '/auth/persona/callback',
data: { 'assertion': assertion },
success: function(data, textStatus, jqXHR) {
Discourse.authenticationComplete(data);
},
dataType: 'json'
});
}
},
onlogout: function() {
if (readyCalled) {
Discourse.logout();
}
},
onready: function() {
readyCalled = true;
}
});
}());
</script>

View File

@ -60,6 +60,7 @@
<footer id='bottom'></footer>
<%= render :partial => "common/discourse_javascript" %>
<%= render :partial => "common/persona_javascript" if SiteSetting.enable_persona_logins %>
<%= render_google_analytics_code %>
<!-- Discourse Version: <%= Discourse::VERSION::STRING %> -->

View File

@ -31,4 +31,7 @@ Rails.application.config.middleware.use OmniAuth::Builder do
SiteSetting.github_client_id,
SiteSetting.github_client_secret
provider :browser_id,
:name => 'persona'
end

View File

@ -251,6 +251,9 @@ en:
github:
title: "Log In with Github"
message: "Authenticating with Github (make sure pop up blockers are not enabled)"
persona:
title: "Log In with Any Email Address (Mozilla Persona)"
message: "Authenticating with Persona (make sure pop up blockers are not enabled)"
composer:
saving_draft_tip: "saving"

View File

@ -340,6 +340,8 @@ en:
github_client_id: "Client id for Github authentication, registered at https://github.com/settings/applications"
github_client_secret: "Client secret for Github authentication, registered at https://github.com/settings/applications"
enable_persona_logins: "Enable email-based authentication with Mozilla Persona"
allow_import: "Allow import, which can replace ALL site data; leave false unless you plan to do data imports"
active_user_rate_limit_secs: "How frequently we update the 'last_seen_at' field, in seconds"