Skip to content

Commit

Permalink
Merge pull request #201 from datasci4health/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
santanche authored Aug 29, 2020
2 parents 59c5002 + 9fd7d24 commit 0955a12
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 125 deletions.
165 changes: 79 additions & 86 deletions src/adonisjs/app/Controllers/Http/AuthController.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,97 @@
/* global use */
'use strict'

const Logger = use('Logger')
// const Logger = use('Logger')

const Env = use('Env')
const axios = use('axios');
var FormData = use('form-data');
const axios = use('axios')
// var FormData = use('form-data')

const { validate } = use('Validator')

const User = use('App/Models/User');
// const User = use('App/Models/User')

class AuthController {

create({ view, session }){
create ({ view, session }) {
return view.render('registration.login', { pageTitle: 'Log in' })
}



async login({ view, request, session, response, auth }) {
try{
const params = request.all()

const messages = {
'email.required': 'Missing email',
'password.required': 'Missing password',
}

const validation = await validate(params, {
email: 'required',
password: 'required',
}, messages)

// * If validation fails, early returns with validation message
if (validation.fails()) {
session
.withErrors(validation.messages())
.flashExcept(['password'])

return response.redirect('back')
}

let endpoint_url = Env.get("HARENA_MANAGER_URL") + "/api/v1/auth/login"

var config = {
method: 'post',
url: endpoint_url,
data: {
email: params.email,
password: params.password,
}
};

await axios(config)
.then(async function (endpoint_response) {

let response_user = endpoint_response.data

await auth.loginViaId(response_user.id)
response.cookie('token', response_user.token)

return response.route('index')
})
.catch(function (error) {
console.log(error);
});
} catch (e){
console.log(e)
}
async login ({ view, request, session, response, auth }) {
try {
const params = request.all()

const messages = {
'email.required': 'Missing email',
'password.required': 'Missing password',
}

const validation = await validate(params, {
email: 'required',
password: 'required'
}, messages)

// * If validation fails, early returns with validation message
if (validation.fails()) {
session
.withErrors(validation.messages())
.flashExcept(['password'])

return response.redirect('back')
}

const endpointUrl = Env.get('HARENA_MANAGER_URL') + '/api/v1/auth/login'

var config = {
method: 'post',
url: endpointUrl,
data: {
email: params.email,
password: params.password
}
}

await axios(config)
.then(async function (endpointResponse) {

const responseUser = endpointResponse.data

await auth.loginViaId(responseUser.id)
response.cookie('token', responseUser.token)

return response.route('index')
})
.catch(function (error) {
console.log(error)
})
} catch (e) {
console.log(e)
}
}



async logout({ session, auth, response, request }){
try{
const endpoint_url = Env.get("HARENA_MANAGER_URL") + "/api/v1/auth/logout"

var config = {
method: 'post',
url: endpoint_url,
headers: {
Authorization: 'Bearer ' + request.cookie('token')
}
};

await axios(config)
.then(async function (endpoint_response) {
await auth.logout()
return response.route('index')
})
.catch(function (error) {
console.log(error);
});
}catch (e){
console.log(e)
}
async logout ({ session, auth, response, request }) {
try {
const endpointUrl = Env.get('HARENA_MANAGER_URL') + '/api/v1/auth/logout'

var config = {
method: 'post',
url: endpointUrl,
headers: {
Authorization: 'Bearer ' + request.cookie('token')
}
}

await axios(config)
.then(async function (endpointResponse) {
await auth.logout()
return response.route('index')
})
.catch(function (error) {
console.log(error)
})
} catch (e) {
console.log(e)
}
}



}

module.exports = AuthController
19 changes: 1 addition & 18 deletions src/adonisjs/app/Controllers/Http/CaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ View.global('currentTime', function () {
})

class CaseController {


create ({ view }) {
return view.render('author.author')
}




async fetch ({ view }) {
const harenaManagerUrl = Env.get('HARENA_MANAGER_URL', 'http://127.0.0.1:1020')
const casesUrl = harenaManagerUrl + '/cases'
Expand All @@ -31,10 +26,6 @@ class CaseController {
})
}





async store ({ view, request, session, response }) {
try {
const params = request.all()
Expand Down Expand Up @@ -131,11 +122,8 @@ class CaseController {
}
}



async getCase ({ view, request, response, params }) {
try {

const endpointUrl = Env.get('HARENA_MANAGER_URL') + '/api/v1/case/' + request.input('id')
// "d2ad02da-b7e1-4391-9f65-4f93eeb4ca7f"
var config = {
Expand Down Expand Up @@ -175,8 +163,6 @@ class CaseController {
return view.render('author.author')
}



async populateModal ({ params, request, view, response }) {
try {
// const params = request.all()
Expand All @@ -194,7 +180,7 @@ class CaseController {
await axios(config)
.then(function (endpointResponse) {
console.log(endpointResponse.data)
// return view.render('author.author')
// return view.render('author.author')

return view.render('author.author')
})
Expand All @@ -205,9 +191,6 @@ class CaseController {
console.log(e)
}
}



}

module.exports = CaseController
4 changes: 2 additions & 2 deletions src/adonisjs/config/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = {
cookie: {
httpOnly: true,
sameSite: false,
path: '/',
path: '/'
// domain:'harena.com'
},

Expand All @@ -81,7 +81,7 @@ module.exports = {
*/
file: {
location: 'sessions'
},
}

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/adonisjs/database/migrations/1503248427885_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UserSchema extends Schema {
this.create('users', (table) => {
table.uuid('id')
table.primary('id')

table.string('username', 80).notNullable().unique()
table.string('email', 254).notNullable().unique()
table.string('password', 60).notNullable()
Expand Down
4 changes: 3 additions & 1 deletion src/adonisjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"App": "./app"
},
"standard": {
"globals": ["use"],
"globals": [
"use"
],
"ignore": [
"public/"
]
Expand Down
1 change: 1 addition & 0 deletions src/adonisjs/public/infra/dcc-common-server-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class DCCCommonServer {
specialty: document.getElementById('specialty').value,
keywords: document.getElementById('keywords').value,
source: document.getElementById('case_source').value
.replace(/\\"/gm, '"')
}
}

Expand Down
18 changes: 1 addition & 17 deletions src/adonisjs/resources/views/author/author.edge
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@
</div>
</div>
<div class="col-2">
<div class="btn-group" role="group" aria-label="Basic example">
<a href="//#" class="btn btn-secondary btn-nav btn-sm"><i class="fas fa-arrow-left"></i> </a>
<a href="//#" class="btn btn-secondary btn-nav btn-sm"><i class="fas fa-arrow-right"></i> </a>
</div>

</div>
</nav>
</div>
Expand All @@ -208,19 +205,6 @@
</dcc-graph>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch2">
<label class="custom-control-label" for="customSwitch2">Thumbnails</label>
</div>
</div>
<div class="col text-right">
<p ><a href="//#">Maximize <i class="fas fa-expand"></i></a></p>
</div>
</div>
</div>
</div>

<div class="w-75 d-flex" id="knot-main">
Expand Down

0 comments on commit 0955a12

Please sign in to comment.