Commit fb5ae3ff authored by Barbora Kompišová's avatar Barbora Kompišová
Browse files

oauth base login

parent b7db3987
import logging
from flask import Blueprint, Flask, Config, url_for, request, redirect, session, jsonify, \
from flask import Blueprint, url_for, request, redirect, session, make_response
from flask_oauthlib.client import OAuth, OAuthRemoteApp
from portal import oauth
from portal.database.models import User
from portal.service import service
from portal.service.service import find_user
log = logging.getLogger(__name__)
......@@ -47,10 +47,6 @@ def oauth_login():
return gitlab.authorize(callback=callback)
def user_oauth_login(user):
def user_oauth_register(user_info):
new_user = User(
......@@ -64,11 +60,11 @@ def user_oauth_register(user_info):
def user_login(user_info):
user = User.query.find_by(username=user_info['user_name'])
user = find_user(user_info['username'])
if not user:
return user_oauth_register(user_info)
resp = make_response(redirect('FRONTEND_URL')))
resp.set_cookie('user_name', user.username)
resp.set_cookie('username', user.username)
return resp
......@@ -30,8 +30,8 @@ class Login(Resource):
raise PortalAPIError(400, message="Missing login type.")
if data['type'] == 'user':
username = data.get('username')
password = data.get('password')
username = data.get('username', None)
password = data.get('password', None)
gitlab_access_token = data.get('gitlab_access_token', None)
client = login_user(gitlab_access_token, password, username)
from portal.service.errors import IncorrectPasswordError, UnauthorizedError
from portal.service.errors import IncorrectPasswordError, UnauthorizedError, PortalAPIError
from portal.service.service import find_user, find_component
......@@ -20,11 +20,17 @@ def auth_gitlab_access_token(username, gitlab_access_token):
Verify that token is for user
username: username of the user attempting to log in
gitlab_access_token: access token string from gitlab
Returns: the authenticated user
if gitlab_access_token is None:
raise PortalAPIError(400, 'No gitlab access token found.')
# TODO: validate gitlab token
user = find_user(username)
return user
def auth_username_password(username, password):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment