def login(): post_body = json.loads(request.data) email = post_body.get('email') password = post_body.get('password') if email is None or password is None: return json.dumps({'success': False, 'error': 'Invalid email or password'}), 400 check= users_dao.get_user_by_email(email) if check is None : if not(isValidEmail(email)) : return json.dumps({'success': False, 'error': 'Wrong email format'}), 400 created, user = users_dao.create_user(email, password) if not created: return json.dumps({'success': False, 'error': 'User already exists'}), 409 return json.dumps({ 'success': True, 'user': [user.serialize()], }), 201 else: success, user = users_dao.verify_credentials(email, password) if not success: return json.dumps({'success': False, 'error': 'Incorrect email or password'}), 400 return json.dumps({ 'success': True, 'user': [user.serialize()], }), 200
def login(): try: post_body = json.loads(request.data) token = post_body['id_token'] idinfo = id_token.verify_oauth2_token( token, requests.Request(), "750288393391-qo22436ht2sgrhinj3o3lfsiivsb0s4i.apps.googleusercontent.com" ) if idinfo['iss'] not in [ 'accounts.google.com', 'https://accounts.google.com' ]: raise ValueError('Wrong issuer.') # return json.dumps(idinfo) userid = idinfo['sub'] email = idinfo['email'] # if email is None or userid is None: # return json.dumps({'error': 'Invalid email or password'}) success, user = users_dao.verify_credentials(email, userid) if not success: return json.dumps({'error': 'Incorrect email or password.'}) return json.dumps({ 'session_token': user.session_token, 'session_expiration': str(user.session_expiration), 'update_token': user.update_token }) except ValueError: # return json.dumps({'error': 'Invalid user id'}) raise ValueError('Invalid Token')
def login(): body = json.loads(request.data) email = body.get("email") password = body.get("password") if email is None or password is None: return json.dumps({"error": "Invalid email or password"}) success, user = users_dao.verify_credentials(email, password) if not success: return json.dumps({"error": "Incorrect email or password."}) return json.dumps({ "session_token": user.session_token, "session_expiration": str(user.session_expiration), "update_token": user.update_token, })
def login(): body = json.loads(request.data) username = body.get("username") password = body.get("password") if username is None or password is None: return json.dumps({"error": "Invalid username or password."}) successful, user = users_dao.verify_credentials(username, password) if not successful: return json.dumps({"error": "Incorrect username or password."}) return json.dumps({ "session_token": user.session_token, "session_expiration": str(user.session_expiration), "update_token": user.update_token, })
def upload_picture(user_id): body = json.loads(request.data) username = body.get("username") password = body.get("password") if username is None or password is None: return failure_response("Invalid username or password") was_successful, user = users_dao.verify_credentials(username, password) if not was_successful: return failure_response("Incorrect username or password") image_data = body.get("image_data") if (image_data is None): return failure_response("No base64 image") asset = Asset(image_data=image_data) db.session.add(asset) db.session.commit() return success_response(asset.serialize())
def login(): post_body = json.loads(request.data) email = post_body.get('email') password = post_body.get('password') if email is None or password is None: return json.dumps({'error': 'Invalid email or password'}) success, user = users_dao.verify_credentials(email, password) if not success: return json.dumps({'error': 'Incorrect email or password'}) return json.dumps({ 'session_token': user.session_token, 'session_expiration': str(user.session_expiration), 'update_token': user.update_token })
def login(): body = json.loads(request.data) username = body.get("username") password = body.get("password") if username is None or password is None: return failure_response("Invalid username or password") was_successful, user = users_dao.verify_credentials(username, password) if not was_successful: return failure_response("Incorrect username or password") return success_response({ "id": user.id, "session_token": user.session_token, "session_expiration": str(user.session_expiration), "update_token": user.update_token, })