-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/QutBioacousticsResearchGr…
- Loading branch information
Showing
23 changed files
with
558 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use strict"; | ||
/** | ||
* The accounts controller. Sign in using external providers. | ||
* @param $scope | ||
* @param $resource | ||
* @param $routeParams | ||
* @constructor | ||
*/ | ||
function AccountsCtrl($scope, $resource, $routeParams) { | ||
|
||
} | ||
|
||
AccountsCtrl.$inject = ['$scope', '$resource', '$routeParams']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<div id="content" data-ng-controller="AccountsCtrl"> | ||
<h1>Accounts Sign In</h1> | ||
<button onclick="login()">login</button> | ||
<button onclick="logout()">logout</button> | ||
|
||
<script type="test/javascript"> | ||
function login() { navigator.id.request(); } | ||
function logout() { navigator.id.request(); } | ||
|
||
var currentUser = '[email protected]'; | ||
|
||
navigator.id.watch({ | ||
loggedInUser: currentUser, | ||
onlogin: function(assertion) { | ||
// A user has logged in! Here you need to: | ||
// 1. Send the assertion to your backend for verification and to create a session. | ||
// 2. Update your UI. | ||
$.ajax({ /* <-- This example uses jQuery, but you can use whatever you'd like */ | ||
type: 'POST', | ||
url: '/security/auth/browser_id/callback', // This is a URL on your website. | ||
data: {assertion: assertion}, | ||
success: function(res, status, xhr) { window.location.reload(); }, | ||
error: function(xhr, status, err) { alert("Login failure: " + err); } | ||
}); | ||
}, | ||
onlogout: function() { | ||
// A user has logged out! Here you need to: | ||
// Tear down the user's session by redirecting the user or making a call to your backend. | ||
// Also, make sure loggedInUser will get set to null on the next page load. | ||
// (That's a literal JavaScript null. Not false, 0, or undefined. null.) | ||
$.ajax({ | ||
type: 'POST', | ||
url: '/security/auth/browser_id/callback', // This is a URL on your website. | ||
success: function(res, status, xhr) { window.location.reload(); }, | ||
error: function(xhr, status, err) { alert("Logout failure: " + err); } | ||
}); | ||
} | ||
}); | ||
</script> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Api::ConfirmationsController < Devise::ConfirmationsController | ||
respond_to :json | ||
|
||
# GET /resource/confirmation/new | ||
def new | ||
resource = build_resource(params[:user]) | ||
respond_with resource | ||
end | ||
|
||
|
||
# POST /resource/confirmation | ||
def create | ||
attributes = params.include?(:user) ? params[:user] : {} | ||
|
||
self.resource = resource_class.send_confirmation_instructions(attributes) | ||
|
||
if successfully_sent?(resource) | ||
respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name)) | ||
else | ||
respond_with(resource) | ||
end | ||
end | ||
|
||
end |
59 changes: 39 additions & 20 deletions
59
app/controllers/registrations_controller.rb → ...ntrollers/api/registrations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
class RegistrationsController < Devise::RegistrationsController | ||
|
||
def update | ||
if params[resource_name][:password].blank? | ||
params[resource_name].delete(:password) | ||
params[resource_name].delete(:password_confirmation) if params[resource_name][:password_confirmation].blank? | ||
end | ||
# Override Devise to use update_attributes instead of update_with_password. | ||
# This is the only change we make. | ||
if resource.update_attributes(params[resource_name]) | ||
set_flash_message :notice, :updated | ||
# Line below required if using Devise >= 1.2.0 | ||
sign_in resource_name, resource, :bypass => true | ||
redirect_to after_update_path_for(resource) | ||
else | ||
clean_up_passwords(resource) | ||
render_with_scope :edit | ||
end | ||
end | ||
|
||
class Api::RegistrationsController < Devise::RegistrationsController | ||
respond_to :json | ||
# see C:\Ruby\193\lib\ruby\gems\1.9.1\gems\devise-2.1.2\app\controllers\devise | ||
|
||
# GET /resource/sign_up | ||
def new | ||
resource = build_resource(params[:user]) | ||
respond_with resource | ||
end | ||
|
||
# POST /resource | ||
def create | ||
user = User.new(params[:user]) | ||
if user.save | ||
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201 | ||
else | ||
warden.custom_failure! | ||
render :json=> user.errors, :status=>422 | ||
end | ||
end | ||
=begin | ||
def update | ||
if params[resource_name][:password].blank? | ||
params[resource_name].delete(:password) | ||
params[resource_name].delete(:password_confirmation) if params[resource_name][:password_confirmation].blank? | ||
end | ||
# Override Devise to use update_attributes instead of update_with_password. | ||
# This is the only change we make. | ||
if resource.update_attributes(params[resource_name]) | ||
set_flash_message :notice, :updated | ||
# Line below required if using Devise >= 1.2.0 | ||
sign_in resource_name, resource, :bypass => true | ||
redirect_to after_update_path_for(resource) | ||
else | ||
clean_up_passwords(resource) | ||
render_with_scope :edit | ||
end | ||
end | ||
=end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
class Api::SessionsController < Devise::SessionsController | ||
|
||
# GET /resource/sign_in | ||
def new | ||
resource = build_resource(nil, :unsafe => true) | ||
clean_up_passwords(resource) | ||
respond_with(resource, serialize_options(resource)) | ||
end | ||
|
||
# POST /resource/sign_in | ||
def create | ||
resource = warden.authenticate!(auth_options) | ||
set_flash_message(:notice, :signed_in) if is_navigational_format? | ||
sign_in(resource_name, resource) | ||
|
||
respond_to do |format| | ||
format.html do | ||
respond_with resource, :location => after_sign_in_path_for(resource) | ||
end | ||
format.json do | ||
# http://stackoverflow.com/questions/9641079/token-authentication-with-rails-and-devise | ||
# http://matteomelani.wordpress.com/2011/10/17/authentication-for-mobile-devices/ | ||
current_user.ensure_authentication_token! | ||
render :json => { :response => 'ok', :auth_token => current_user.authentication_token }.to_json, :status => :ok | ||
end | ||
end | ||
|
||
end | ||
|
||
=begin | ||
before_filter :authenticate_user!, :except => [:create, :destroy] | ||
before_filter :ensure_params_exist | ||
respond_to :json | ||
# see http://jessewolgamott.com/blog/2012/01/19/the-one-with-a-json-api-login-using-devise/ | ||
def create | ||
resource = User.find_for_database_authentication(:email => params[:user_login][:email]) | ||
return invalid_login_attempt unless resource | ||
if resource.valid_password?(params[:user_login][:password]) | ||
sign_in(:user, resource) | ||
resource.ensure_authentication_token! | ||
render :json=> {:success=>true, :auth_token=>resource.authentication_token, :email=>resource.email} | ||
return | ||
end | ||
invalid_login_attempt | ||
end | ||
def destroy | ||
resource = User.find_for_database_authentication(:email => params[:user_login][:email]) | ||
resource.authentication_token = nil | ||
resource.save | ||
render :json=> {:success=>true} | ||
end | ||
protected | ||
def ensure_params_exist | ||
return unless params[:user_login].blank? | ||
render :json => { :success => false, :message => "Missing user_login parameter." }, :status => 422 | ||
end | ||
def invalid_login_attempt | ||
render :json => { :success => false, :message => "Login was not successful." }, :status => 401 | ||
end | ||
=end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class ProjectsController < ApplicationController | ||
|
||
# GET /projects | ||
# GET /projects.json | ||
def index | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.