def register(): try: email = str(request.form['email']) password = str( app.bcrypt.generate_password_hash(request.form['password'])) phone = request.form['phone'].replace("-", "") try: airdrop = request.form['airdrop'] except Exception as e: print(e) airdrop = "" auth.User(email=email, password=password, phone=phone, airdrop=airdrop).save() return jsonify({ "success": True, "msg": "successful created new user", "wallet": "", "accessToken": app.create_access_token(identity={ "email": email, "wallet": "" }) }), 200 except Exception as e: print(e) return Error.id_or_phone_overlapped()
def post(self): parser = reqparse.RequestParser(bundle_errors=True) parser.add_argument('username', type=str, required=True, help="Username cannot be blank!", location='json') parser.add_argument('password', type=str, required=True, help="password cannot be blank!", location='json') args = parser.parse_args() try: if args['username'] and args['password'] is not None: username = args['username'] password = args['password'] if username and password is not None: query_user= """ SELECT PASSWORD FROM USERS WHERE USERNAME = %s """ params = (username,) row = readSQL(query_user, params) status = app.bcrypt.check_password_hash(row['password'], password) if status: access_token = app.create_access_token(identity=username) return { 'success' : True, 'token': access_token }, 200 else: return { 'success' : False }, 404 else: return { 'success' : False }, 400 except Exception as e: app.log.exception(e) return {'success': False, 'message': "SERVER/DB error" }, 500
def post(self): data = api.payload if UserModel.check_email_exists(data['email']): if UserModel.validate_password(data['email'], data['password']): #after a successful login uid = UserModel.get_user_id(data['email']) token = create_access_token(identity=uid) return {'access_token': token}, 200 else: return {'Message': 'incorrect login credentials'}, 401 else: return {'Message': 'incorrect login credentials'}, 401
def post(self): data = api.payload email = data['email'] user_id = UserModel.get_user_id(email) if UserModel.does_email_exists(email): if UserModel.validate_password(email, data['password']): return { 'message': 'login successful', 'access_token': create_access_token(identity=user_id) } else: return {'message': 'Invalid login credentials'} else: return {'message': 'Invalid login credentials'}
def create_token(cls, _id, role, fresh=True): "create access and refresh token for user" access_token = create_access_token({ \ "_id":_id, "role":role}, fresh=datetime. \ datetime.utcnow(), expires_delta \ =datetime.timedelta(minutes=120)) if fresh == True: refresh_token = create_refresh_token({ \ "_id":_id, "role":role}, \ expires_delta=datetime.\ timedelta(minutes=180)) else: refresh_token = None return {"access_token": access_token, "refresh_token": refresh_token}
def login(): if request.json: name = request.json.get('name', None) password = request.json.get('password', None) try: u = User.query.filter_by(name=name).first() if u and u.password == password: token = create_access_token(identity=name) return http_response(200, 'ok', token) else: return http_response(250, 'bad', 'user illegal') except: return http_response(500, 'bad', 'login failed') return http_response(250, 'bad', 'json data required')
def login(): email = str(request.form['email']) password = str(request.form['password']) master_object = admin.Master.objects(email=email) if len(master_object) == 0: return Error.invalid_input() else: if app.bcrypt.check_password_hash(str(master_object[0].password), password): return jsonify({ "success": True, "type": "master", "accessToken": app.create_access_token(identity={"role": "master"}) }), 200 else: return Error.wrong_password()
def login(): email = str(request.form['email']) password = str(request.form['password']) user_object = admin.Admin.objects(email=email) if len(user_object) == 0: return Error.user_not_found() else: if app.bcrypt.check_password_hash(eval(user_object[0].password), password): return jsonify({ "success": True, "accessToken": app.create_access_token(identity={ "role": "admin", "email": user_object[0].email }) }), 200 else: return Error.wrong_password()
def get_token(): data = MyForm( Field("emailAddress", is_mandatory=True, validators=[validators.is_string]), Field("key", is_mandatory=True, validators=[validators.is_string]), Field("secret", is_mandatory=True, validators=[ validators.is_string, ]), ).get_data() try: api_access_pair = ApiAccessPair.query.filter_by( key=data["key"], secret=data["secret"]).one() except (NoResultFound, MultipleResultsFound): raise InvalidUsage("access pair not found", 401) if api_access_pair.user.email_address != data["emailAddress"]: raise InvalidUsage( "incorrect email address for access pair: {0}".format( data["emailAddress"]), 401) if not api_access_pair.enabled: raise InvalidUsage("access pair is disabled", 401) access_token, expires_at = create_access_token( api_access_pair.user.appen_id) current_app.logger.info("access token created for user {0}: {1}".format( api_access_pair.user.appen_id, access_token)) return jsonify({ "accessToken": access_token, "expiresAt": expires_at, "appenId": api_access_pair.user.appen_id, })
def login(): email = str(request.form['email']) password = str(request.form['password']) user_object = auth.User.objects(email=email) if len(user_object) == 0: return Error.invalid_input() else: if app.bcrypt.check_password_hash(eval(user_object[0].password), password): return jsonify({ "success": True, "wallet": user_object[0].wallet, "accessToken": app.create_access_token( identity={ "email": user_object[0].email, "wallet": user_object[0].wallet }) }), 200 else: return Error.wrong_password()
def login(password): if password == admin_password: token = create_access_token(identity='admin') return {'success': True, 'token': token} else: return {'success': False, 'token': ''}