def logout(email): token = Redis.get(email) if token: Redis.delete(email) return {"message": "success"}, 204 else: abort(401, 'could not find token user')
def withdrawal(email): del_user = session.query(User).filter(User.email == email).first() if del_user: token = Redis.get(email) if token: Redis.delete(email) session.delete(del_user) session.commit() return {"message": "success"}, 204 else: abort(401, 'could not find user')
def send_email_code(email): user = session.query(User).filter(User.email == email).first() if user: abort(409, 'this email is already in use') code = f"{random.randint(111111, 999999):04d}" title = "GRAMO 이메일 인증 메일" content = f"이메일 인증 코드는 {code}입니다." send_email(title=title, content=content, adress=email) Redis.setex(name=email, value=code, time=180) return {"message": "success"}, 200
def check_reset_code(email, code): reset_code = Redis.get(email + "reset").decode('utf-8') if reset_code == code: return True else: return False
def check_auth_code(email, code): auth_code = Redis.get(email + "auth").decode('utf-8') if auth_code == code: return {"message": "Successfully authenticated"} else: return abort(401, "The verification code is not correct")
def check_code(email, code): stored_code = Redis.get(email) if not stored_code: abort(404, 'this email does not exist') if int(stored_code) != int(code): abort(409, 'email and code does not match') return {"message": "success"}, 200
def login(email, password): user = session.query(User).filter(User.email == email).first() if user: check_user_pw = check_password_hash(user.password, password) if check_user_pw: access_token = create_access_token(identity=email) refresh_token = create_refresh_token(identity=email) Redis.setex(name=email, value=refresh_token, time=604800) return { "name": user.name, "major": user.major, "access_token": access_token, "refresh_token": refresh_token }, 201 else: abort(404, 'email and password does not match') else: abort(404, 'email and password does not match')
def save_code_into_redis(email, auth_code, codetype): Redis.set(email + codetype, auth_code, timedelta(minutes=5))