def token(): """토큰 등록 :status 200: 요청완료 :status 400: 폼데이터 오류 :status 401: 로그인 필요 :status 500: 서버 오류 **성공 response**: .. sourcecode:: http HTTP/1.1 200 OK **실패 response**: .. sourcecode:: http HTTP/1.1 500 Internal Server Error """ token = request.form.get('token', type=str) if token is None: return '', 400 user = User.query().filter_by(id=g.user.id) try: user.update({'push_token': token}) db.session.commit() except: db.session.rollback() return '', 500 return '', 200
def signUp(): """회원 가입 :form uuid: 디바이스 uuid :type uuid: str :form name: 이름 :type name: str :status 201: 요청 완료 :status 400: 잘못된 데이터 :status 409: 이미 존재하는 유저 :status 500: 서버 오류 **성공 response**: .. sourcecode:: http HTTP/1.1 201 CREATED **에러 response**: .. sourcecode:: http HTTP/1.1 400 BAD REQUEST """ uuid = request.form.get('uuid', type=str) name = request.form.get('name', type=str) if uuid is None: return '', 400 if name is None: return '', 400 user = User.query.filter_by(uuid=uuid).first() if user is not None: session['user_id'] = user.id return '', 201 try: role = Role.query.filter_by(name='user') user = User(name=name, uuid=uuid, roles=role) db.session.add(user) db.session.commit() except Exception as e: db.session.rollback() print(e) return '', 500 session['user_id'] = user.id return '', 201
def user_resource(db_session): """A User called 'test'.""" resource = User(user_name='test', email_address='*****@*****.**', password_hash='x', full_name='Dummy User', info_status='[]', attributes='{}', deleted=False, creation_timestamp=datetime.datetime.utcnow(), role=User.STANDARD_USER) db_session.add(resource) return resource
def create_user(email_address, user_name, password, full_name, role): user = User() user.email_address = email_address user.user_name = user_name if user_name else None # use NULL instead of empty string user.password_hash = hash_password(password) user.full_name = full_name user.info_status = '{}' user.attributes = '{}' user.deleted = False user.creation_timestamp = datetime.datetime.utcnow() user.role = role db.session.add(user) db.session.commit() return user.id