'use strict'
let Action = require('../db').Action

exports.get = function (request, response) {
  if (request.isUnauthenticated()) {
    request.session.legacy = "true"
    response.render('login.swig', request.query)
  } else {
    Action.create({
      inet: request.inet,
      type: 'login',
      userId: request.user.id
    })
    if (request.session.returnTo) {
      response.redirect(request.session.returnTo)
      delete request.session.returnTo
    } else {
      response.redirect('/welcome')
    }
  }
}





exports.post = function (request, response, next) {
  request.session.userIp = request.headers['x-Forwarded-For'] || request.connection.remoteAddress

  request.session.errorCode = 401 // This could signify that the login has failed
  response.redirect('/login?error_login=1')
}

@@ -159,14 +159,12 @@
 y = 
-%22
 true
-%22
 %0A   
@@ -566,16 +566,226 @@
 next) %7B%0A
+  if (request.user) %7B%0A    if (request.session.legacy) %7B%0A      return response.redirect('/login')%0A    %7D else %7B%0A      response.model.data = request.user%0A      response.status(200)%0A      next()%0A    %7D%0A  %7D else %7B%0A  
   reques
@@ -875,16 +875,18 @@
 ddress%0A%0A
+  
   reques
@@ -959,16 +959,18 @@
  failed%0A
+  
   respon
@@ -1005,10 +1005,14 @@
 gin=1')%0A
+  %7D%0A
 %7D%0A

Fix login not actually returning a valid response to when not requested by the user form