Skip to content

Commit

Permalink
Second Beta Release.
Browse files Browse the repository at this point in the history
Added JWT for authentication.
Added Route Based Authentication.

Added DataSeeder
Added Auth Functions and Routes

..... and many more bug fixes
  • Loading branch information
Sithira committed Jun 16, 2018
1 parent 274f598 commit b1f2119
Show file tree
Hide file tree
Showing 35 changed files with 1,998 additions and 1,855 deletions.
165 changes: 85 additions & 80 deletions app/Controllers/Http/Auth/LoginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,91 @@

class LoginController
{

/**
* Login the user.
*
* @param request
* @param response
* @param auth
* @return {Promise<*>}
*/
async login({request, response, auth})
{

const {
email,
password
} = request.all();

let payLoad = await auth
.withRefreshToken()
.attempt(email, password);

return response.status(200).json({
status: "OK",
data: payLoad
});

}

async refreshToken({request, response, auth})
{



}

/**
* Logout the currently logged in user.
*
* @param request
* @param response
* @param auth
* @return {Promise<*>}
*/
async logout({request, response, auth})
{

try {

await auth.logout();

return response.status(200).json({
status: "OK",
message: "Successfully Logged out"
});

}
catch (error)
{
throw new Error(error);
}

}

async check({request, response, auth})
{
try {
await auth.check();

return response.status(403).json({
status: "OK",
message: "Authenticated"
})
} catch (error) {
return response.status(403).json({
status: "ERROR",
message: error
})
}
}


/**
* Login the user.
*
* @param request
* @param response
* @param auth
* @return {Promise<*>}
*/
async login({request, response, auth})
{

// get the details from the request body.
const {
email,
password
} = request.all();

// exchange an access_token for email and password
let payLoad = await auth
.withRefreshToken()
.attempt(email, password);

// return the response
return response.status(200).json({
status: "OK",
data: payLoad
});

}

async refreshToken({request, response, auth})
{


}

/**
* Logout the currently logged in user.
*
* @param request
* @param response
* @param auth
* @return {Promise<*>}
*/
async logout({request, response, auth})
{

try
{

await auth.logout();

return response.status(200).json({
status: "OK",
message: "Successfully Logged out"
});

}
catch (error)
{
throw new Error(error);
}

}

async check({request, response, auth})
{
try
{
await auth.check();

return response.status(403).json({
status: "OK",
message: "Authenticated"
})
} catch (error)
{
return response.status(403).json({
status: "ERROR",
message: error
})
}
}

}

module.exports = LoginController;
29 changes: 27 additions & 2 deletions app/Controllers/Http/Auth/ProfileController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
'use strict'
'use strict';

class ProfileController {
class ProfileController
{

async index({request, response, auth})
{

try
{
let user = await auth.getUser();

return response.status(200).json({
status: "OK",
authentication: "AUTHENTICATED",
data: user
})
}
catch (err)
{
return response.status(302).json({
status: "ERROR",
message: "Please Re-Login"
})
}

}

}

module.exports = ProfileController;
Loading

0 comments on commit b1f2119

Please sign in to comment.