• Y
  • List All
  • Feedback
    • This Project
    • All Projects
Profile Account settings Log out
  • Favorite
  • Project
  • All
Loading...
  • Log in
  • Sign up
yjyoon / Daegu-Jeju-DIP star
  • Project homeH
  • CodeC
  • IssueI
  • Pull requestP
  • Review R
  • MilestoneM
  • BoardB 1
  • Files
  • Commit
  • Branches
Daegu-Jeju-DIPauth.py
Download as .zip file
File name
Commit message
Commit date
database
rebulding server
2024-09-09
logger
Hello Yona
2024-07-09
.gitignore
massive modification, this is the part where DB gets cryptography, extended functionality support for the application
2024-09-06
README.md
Hello Yona
2024-07-09
action.py
rebulding server
2024-09-09
app.py
massive modification, this is the part where DB gets cryptography, extended functionality support for the application
2024-09-06
auth.py
rebulding server
2024-09-09
blocked_ips.json
Hello Yona
2024-07-09
example.json
added json communication format
2024-07-17
unit_test_insert_gps_command.sh
added another boundary condition : this is for when the data itself is incomplete, where its missing some one or two data
2024-07-17
juni 2024-09-09 f5e18f3 rebulding server DOS
Raw Open in browser Change history
from flask import request,jsonify,render_template,redirect,url_for from flask_restx import Resource, Api, Namespace, fields from database.database import DB import datetime import jwt users = {} Auth = Namespace( name="Auth", description="사용자 인증을 위한 API", ) user_fields = Auth.model('User', { # Model 객체 생성 'id': fields.String(description='a User Name', required=True, example="id") }) user_fields_auth = Auth.inherit('User Auth', user_fields, { 'password': fields.String(description='Password', required=True) }) get_phone_number = Auth.inherit('get a phone number of an user', { 'id' : fields.String(description="user id", required=True) }) get_email = Auth.inherit('get an email of an user', { 'id' : fields.String(description="user id", required=True) }) user_fields_register = Auth.inherit('User reigster', user_fields, { 'password': fields.String(description='Password', required=True),'email': fields.String(description='email', required=True),'user_sex': fields.String(description='sex', required=True),'phone': fields.String(description='phone', required=True) }) @Auth.route('/id') class AuthCheck(Resource): @Auth.doc(responses={200: 'Success'}) @Auth.doc(responses={500: 'Register Failed'}) def post(self): db=DB() id = request.json['id'] value=db.db_check_id(id) if value != None: return { "message": "중복 아이디가 있습니다" }, 500 else: return { 'message': '사용가능한 아이디입니다' # str으로 반환하여 return }, 200 @Auth.route('/register') class AuthRegister(Resource): @Auth.expect(user_fields_register) @Auth.doc(responses={200: 'Success'}) @Auth.doc(responses={500: 'Register Failed'}) def post(self): user_manager = DB() # Extract data from the request data = request.json id_ = data['id'] password = data['password'] user_email = data['email'] sex = data['user_sex'] phone = data['phone'] # Prepare data for registration user_data = { 'username': id_, 'password': password, 'email': user_email, 'sex': sex, 'phone': phone } # Call the register_user method from the UserManager instance result, status_code = user_manager.register_user(user_data) # Return the appropriate response based on the result from UserManager if status_code == 200: return result, 200 else: return result, 500 @Auth.route('/retrive_phone_number') class AuthRegister(Resource): @Auth.expect(get_phone_number) @Auth.doc(responses={200: 'Success'}) @Auth.doc(responses={500: 'Register Failed'}) def post(self): user_manager = DB() data = request.json id_ = data['id'] query_input = { "username" : id_ } result, status_code = user_manager.get_phone_number(query_input) if status_code == 200: return result, 200 else: return result, 500 @Auth.route('/retrive_email') class AuthRegister(Resource): @Auth.expect(get_email) @Auth.doc(responses={200: 'Success'}) @Auth.doc(responses={500: 'Register Failed'}) def post(self): user_manager = DB() data = request.json id_ = data['id'] query_input = { "username" : id_ } result, status_code = user_manager.get_email(query_input) if status_code == 200: return result, 200 else: return result, 500 @Auth.route('/login') class AuthLogin(Resource): @Auth.expect(user_fields_auth) @Auth.doc(responses={200: 'Login Successful'}) @Auth.doc(responses={401: 'Unauthorized'}) @Auth.doc(responses={500: 'Login Failed'}) def post(self): user_manager = DB() # Extract data from the request data = request.json id_ = data['id'] password = data['password'] # Prepare data for authentication user_data = { 'username': id_, 'password': password } # Call the login_user method from the UserManager instance result, status_code = user_manager.login_user(user_data) if result['status'] == 'success': payload = { 'id': id, 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=14) } token = jwt.encode(payload, "secret", algorithm='HS256') return jsonify({'result': 'success', 'token': token}) else : return jsonify({'result': 'fail', 'msg': '아이디/비밀번호가 일치하지 않습니다.'}) @Auth.route('/secession') class AuthSecession(Resource): def post(self): db=DB() id = request.json['token'] payload = jwt.decode(id, "secret", algorithms=['HS256']) db.db_delete_id(payload['id']) return {'secession':'success'}

          
        
    
    
Copyright Yona authors & © NAVER Corp. & NAVER LABS Supported by NAVER CLOUD PLATFORM

or
Sign in with github login with Google Sign in with Google
Reset password | Sign up