def wrapped(*args, **kwds): #TODO(martinis) add tests if 'client_version' in request.args: if request.args['client_version'] != app.config['CLIENT_VERSION']: logging.info( "Client out of date. Client version {} != {}".format( request.args['client_version']), app.config['CLIENT_VERSION']) return utils.create_api_response(403, "incorrect client version", { 'supplied_version': request.args['client_version'], 'correct_version': app.config['CLIENT_VERSION'] }) user = auth.authenticate() if not isinstance(user, models.User): return user session['user'] = user logging.info("User is %s.", user.email) try: return view(*args, **kwds) except (WebArgsException, BadValueError) as e: message = "Invalid arguments: %s" % e.message logging.warning(message) return utils.create_api_response(400, message) except Exception as e: #pylint: disable=broad-except #TODO(martinis) add tests error_message = traceback.format_exc() logging.error(error_message) return utils.create_api_response(500, 'internal server error:\n%s' % error_message)
def test_auth(self): passwd = 'unit_test_pass' u = User(nickname = 'UnitTester', email = '*****@*****.**', pwhash=crypt(passwd)) db.session.add(u) db.session.commit() u = User.query.filter_by(email='*****@*****.**').first() assert u is None assert authenticate('*****@*****.**', passwd)
def login(self): username = request.json['username'] password = request.json['password'] user = auth.authenticate(username, password) if user: auth.logout_user() auth.login_user(user) return response_manager.LOGIN_SUCCESS_RESPONSE else: return response_manager.LOGIN_FAILED_RESPONSE
def login(): data = request.get_json() user = auth.authenticate(**data) if not user: return jsonify({ 'message': 'Invalid credentials', 'authenticated': False }), 401 token = jwt.encode({ 'sub': user.Login, 'iat':datetime.utcnow(), 'exp': datetime.utcnow() + timedelta(minutes=600)}, current_app.config['SECRET_KEY']) user_type = UserType.query.filter_by(Type_id = user.Type_id).first() return jsonify({ 'token': token.decode('UTF-8'), 'userType': user_type.Type_name, 'userName': user.FIO })
def login(): form = gf.Map(request.form.to_dict()) user_ = auth.authenticate(form.username,form.password) if user_ and user_["isAuthenticated"]: if auth.Adminuser["session"] is None: auth.Adminuser["session"] = api.createSession(user_) return render_template("index.html",title="Meteriod",year=gf.year(),user=user_) return render_template("login.html",title="Meteriod | Login",form=[1],user=user_) return render_template("login.html",title="Meteriod | Login",form=[1],user=user_)
def login(): """ TODO """ body = loads(request.data) token = auth.authenticate(body["username"], body["password"]) if not token: return make_response("failed to authenticate", 400) response = {"token": token, "username": body["username"]} return make_response(jsonify(response), 200)
async def login(db: Session = Depends(deps.get_db), form_data: OAuth2PasswordRequestForm = Depends()) -> Any: user = authenticate(email=form_data.username, password=form_data.password, db=db) if not user: raise HTTPException(status_code=400, detail="Incorrect username or password") user_jwt_payload = get_user_jwt_payload(user) return { "access_token": create_access_token(user.id, user_jwt_payload), "token_type": "bearer", }
def login(): if request.method == "POST": user = auth.authenticate(email=request.form['email'], password=request.form['password']) if user is None: flash("Incorrect Credentials", "danger") return redirect(url_for('admin.login')) else: if user.is_admin: flash("Successfully Logged In", "success") session['quizadmin'] = user.id return redirect(url_for('admin.homepage')) else: flash("Incorrect Credentials You Are Not Admin User", "danger") return redirect(url_for('admin.login')) else: return render_template("admin/login.html")
def api_wrapper(*args, **kwds): #TODO(martinis) add tests # Any client can check for the latest version try: request.fields = {} message = "success" if request.args.get('client_version'): check_version(request.args['client_version']) user = auth.authenticate() if not isinstance(user, models.User): return user session['user'] = user logging.info("User is %s.", user.email) rval = view(*args, **kwds) if (isinstance(rval, Response) or isinstance(rval, werkzeug.wrappers.Response)): pass elif isinstance(rval, list): rval = utils.create_api_response(200, message, rval) elif (isinstance(rval, collections.Iterable) and not isinstance(rval, dict)): rval = utils.create_api_response(*rval) else: rval = utils.create_api_response(200, message, rval) return rval except IncorrectVersionError as e: logging.warn(e.message) return utils.create_api_response(e.code, e.message, e.data) except APIException as e: logging.exception(e.message) return utils.create_api_response(e.code, e.message, e.data) except Exception as e: #pylint: disable=broad-except logging.exception(e.message) return utils.create_api_response(500, 'internal server error :(')
def is_accessible(self): if not auth.authenticate(): raise AuthException("Not authenticated.") else: return True
async def user_login(form: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_db)): user = authenticate(db=db, username=form.username, password=form.password) return create_tokens(db=db, user_id=user.id)