Basic authentification with EmberJs and Laravel
Written by Bastien Donjon, Posted in Javascript, PHP
The following example uses the ember-simple-auth plugin. This is an early implementation for the Basic authentication with Laravel session and RestFul Api.
Currently, it can :
- Require authentication to the IndexRoute and DashboardRoute
- Refresh authentication if you refresh the page
Not being a specialist EmberJs this code is incomplete like :
- Retrieving information form
- Error handling in a loss of authentication with an API call
- Proper use of the accessToken property
For safety reasons use the HTTPS protocol.
I am at your service if you have any comments or questions.
Ember configuration
Template : login.hbs
</pre>
<form action=""><label for="identification">Login</label>
{{input id='identification' placeholder='Enter Login' value=identification}}
<label for="password">Password</label>
{{input id='password' placeholder='Enter Password' type='password' value=password}}
<button type="submit">Login</button></form>
<pre>
app.js
// Defining a custom authentication with Basic method.
var CustomAuthenticator = Ember.SimpleAuth.Authenticators.Base.extend({
// Check session if you refresh browser (F5)
restore: function(properties) {
return new Ember.RSVP.Promise(function(resolve, reject){
Ember.$.ajax({
url: 'http://localhost.com/api/guest',
success : function(datas){
resolve(properties);
},
error: function(datas){
reject();
}
});
});
},
// Initialized authentification
authenticate: function(options) {
return new Ember.RSVP.Promise(function(resolve, reject){
Ember.$.ajax({
url: 'http://localhost.com/api/profile',
success : function(datas){
resolve({accessToken : 'fddfgdfgfdgfg'});
},
headers: {
"Authorization": "Basic " + btoa("email4@domain.fr:password4")
}
});
});
},
invalidate: function(options) {
return new Ember.RSVP.Promise(function(resolve, reject){
Ember.$.ajax({
url: 'http://localhost.com/api/logout',
success : function(datas){
resolve({accessToken : 'fddfgdfgfdgfg'});
}
}).then(function(response){
Ember.run(resolve);
}, function(xhr, status, error){
Ember.run(reject);
});
});
}
});
// Initialied a custom authentication.
Ember.Application.initializer({
name: 'authentication',
initialize: function(container, application) {
container.register('authenticators:custom', CustomAuthenticator);
Ember.SimpleAuth.setup(container, application);
}
});
BackendWebapp.LoginController = Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin, {
authenticatorFactory: 'authenticators:custom'
});
// Add authentification for Route Index
BackendWebapp.IndexRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin);
// Add authentification for DashBoardIndex
BackendWebapp.IndexRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin);
Laravel configuration
route.php
// Logout current user
Route::get('/logout', function(){
Auth::logout();
});
// Chech current authentification state
Route::get('/guest', function(){
if(Auth::guest()){
throw new \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException();
}else{
echo 'ok';
}
});
filters.php
Change Authentification method “Basic” to “x-Basic” to desactivate authentification popup in Google Chrome with ajax request.
Route::filter(
'auth.basicCustom', function () {
$credentials = [ 'email' => Request::getUser(), 'password' => Request::getPassword() ];
if (!Auth::once($credentials)) {
throw new \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException('x-Basic');
}
}
);
sources :
Scuzx4U5uMZ
6K6IKbCbtfc
sqdKBn7NHom
06bzEQR7LF4
RQ6kkVjZG4k
hoYYfGxTRrF
ipppkoDmXaA
TuCpa3ZHwfj
UTDJmGX28W7
pvphfiRUXAf
wGFRU3L3rB7
RREK44CD52f
rwcktKXuYZr
PEcgODjTHUR
nfammhukwDw
Et3gHW4XDI6
TuCHCsA1nGb
BipjSz7AxnM
5h25dWh4iul
pBMqkbxkVxE
LSbXIN1eDkC
WDDs2Q9hMYT
rvB2IRxDAy1
je0As4iNsNi
lErLvi92VNW
VAjEkRqXSuy
rJUHUBbGtaS
KaA8pHqs0F5
uNytSiAVBwl
hV0v1WpTyVN
5su4SfMiNVO
wbIP8q4Jez4
n2pGXLFeU5p
BuCo1BySvlG
Vt9jUtc1FoX
Nr6ySrKYJno
Alright y’all, gk88slot is where it’s at for slots. Seriously, some great games and jackpots on offer. Stumbled upon it, and very happy with my find. See if you like it at gk88slot.
Heard whispers about Code78win? Let me tell ya, it’s been catching my eye lately. Gotta check them out and see what the buzz is all about! Is anyone else playing there? code78win
Interesting points! Seeing more platforms like bigbunny ph game focusing on data-driven fairness is great for PH players. Transparency & secure registration (like they emphasize) build trust, crucial in online gaming! 🤔
Gave ph333casino a shot last week. Gotta say, I was pleasantly surprised. The variety of games is solid, and I actually managed to win a bit! Give it a whirl: ph333casino. Good luck!
Logging into ph3333casinologin was uncomplicated. Zero hassles. Here’s the link to give access!: ph3333casinologin.
Stumbled across ph33m the other day, and it seems… interesting. I didn’t spend too much time on it, but it might be worth checking out if you’re bored. Here’s the link: ph33m.
Categories
Recent Posts
Mes sites
Archives