Skip to content

Instantly share code, notes, and snippets.

View marcoow's full-sized avatar
🙈
🙉🙊

Marco Otte-Witte marcoow

🙈
🙉🙊
View GitHub Profile
App.SessionNewController = Ember.Controller.extend({
login: function() {
var self = this;
var data = this.getProperties('loginOrEmail', 'password');
if (!Ember.isEmpty(data.loginOrEmail) && !Ember.isEmpty(data.password)) {
var postData = { session: { login_or_email: data.loginOrEmail, password: data.password } };
$.post('/session', postData).done(function(response) {
var sessionData = (response.session || {})
App.Session.setProperties({
authToken: sessionData.auth_token,
App.Router.map(function() {
this.resource('session', function() {
this.route('new');
this.route('destroy');
});
});
class ApplicationController < ActionController::Base
def current_user
@current_user ||= begin
auth_token = request.env['HTTP_X_AUTHENTICATION_TOKEN']
Account.find_by(auth_token: auth_token) if !!auth_token
end
end
end
@marcoow
marcoow / store.js
Last active December 20, 2015 19:39
App.AuthenticatedRESTAdapter = DS.RESTAdapter.extend({
ajax: function(url, type, hash) {
hash = hash || {};
hash.headers = hash.headers || {};
hash.headers['X-AUTHENTICATION-TOKEN'] = App.Store.authToken;
return this._super(url, type, hash);
}
});
@marcoow
marcoow / session.js
Last active December 20, 2015 19:38
Ember.Application.initializer({
name: 'session',
initialize: function(container, application) {
App.Session = Ember.Object.extend({
init: function() {
this._super();
this.set('authToken', $.cookie('auth_token'));
this.set('authAccountId', $.cookie('auth_account'));
},
= 1.7.2
* fixed Simplabs::Excellent::Checks::Rails::CustomInitializeMethodCheck
* fixed Simplabs::Excellent::Checks::MethodNameCheck so it allows method names that exist in Ruby itself
* fixed Simplabs::Excellent::Checks::GlobalVariableCheck so it doesn't report false positives for rescue bodies
* made the parser more forgiving/stable in some situations
@marcoow
marcoow / auth_manager.js
Last active December 18, 2015 14:19
authentication manager that handles everything related to client authgentication
App.AuthManager = Ember.Object.extend({
init: function() {
this._super();
var authToken = $.cookie('auth_token');
var authAccountId = $.cookie('auth_account');
if (!Ember.isEmpty(authToken) && !Ember.isEmpty(authAccountId)) {
this.authenticate(authToken, authAccountId);
}
},
@marcoow
marcoow / session.js
Created June 17, 2013 12:26
ember.js session model
App.Session = DS.Model.extend({
authToken: DS.attr('string'),
account: DS.belongsTo('App.Account')
});
@marcoow
marcoow / authenticated_controller.rb
Created June 17, 2013 12:24
Rails controller that ensures a user is authenticated
class AuthenticatedController < ApplicationController
ensure_authenticated_user
end
@marcoow
marcoow / authenticated_route.js
Created June 17, 2013 12:21
authenticated route class that ensures a user is authenticated and otherwise redirects to sessions/new
App.AuthenticatedRoute = Ember.Route.extend({
enter: function() {
if (!Ember.isEmpty(App.Auth.get('authToken')) && !Ember.isEmpty(App.Auth.get('accountId'))) {
this.transitionTo('sessions.new');
}
}
});