Example #1
0
 def get(self):
     '修改邮箱验证状态'
     data = self.parser.parse_args()
     user = User.verify_auth_token(data.get('id'))
     if not user:
         abort(404)
         return None
     user.confirmed = True
     db.session.commit()
     return success_msg()
Example #2
0
 def get(self):
     '获取指定房间信息'
     request_data = self.parser.parse_args()
     room_id = request_data.get('room_id')
     room = Room.query.filter_by(id=room_id).first()
     if not room:
         return fail_msg(msg='该房间不存在')
     data = room.get_data()
     data['roommates'] = room.get_name()
     return jsonify(success_msg(data=data))
Example #3
0
 def delete(self):
     '离开房间'
     if not g.user.joined_room:
         return fail_msg('你未在任何一个房间')
     room = g.user.roommember[0].room
     db.session.delete(g.user.roommember[0])
     room.count = room.count - 1
     g.user.joined_room = False
     db.commit()
     return success_msg('房间离开成功!')
Example #4
0
 def put(self):
     '修改密码(需原密码)'
     form = ChangePasswordForm()
     if not form.validate_on_submit():
         return fail_msg(msg='输入错误!')
     if g.error:
         return g.error
     user = g.user
     user.hash_password(form.password.data)
     db.session.commit()
     return success_msg()
Example #5
0
 def post(self):
     '新建用户'
     form = SignupForm()
     if not form.validate_on_submit():
         return fail_msg(msg='输入错误!')
     if g.error:
         return g.error
     user = User(username=form.username.data, email=form.email.data)
     user.hash_password(form.password.data)
     # send_email()  # 此处以后再修改
     db.session.add(user)
     db.session.commit()
     return success_msg()
Example #6
0
 def get(self):
     '获取当前用户及房间信息'
     data = {}
     user = g.user
     data['user'] = user.get_data()
     data['room'] = {}
     data['roommates'] = []
     if user.joined_room:
         room = user.roommember[0].room
         data['room'] = room.get_data()
         for rm in room.roommembers:
             data['roommates'].append(rm.get_data())
     return jsonify(success_msg(data=data))
Example #7
0
 def post(self):
     '修改密码(需要邮箱已验证)[此处仅验证邮箱及发送邮件]'
     form = ForgetPasswordForm()
     if not form.validate_on_submit():
         return fail_msg(msg='输入错误!')
     if g.error:
         return g.error
     user = User.query.filter_by(username=form.username.data,
                                 email=form.email.data).first()
     if not user:
         return fail_msg('该用户不存在!')
     # send_email()  # 此处以后再修改
     return success_msg(msg="邮件已发送")
Example #8
0
 def delete(self):
     '房间创建者删除房间'
     user = g.user
     if not user.joined_room:
         return fail_msg('你未在任何一个房间')
     room = g.user.roommember[0].room
     if user.id != room.owner_id:
         return fail_msg('非创建者无权删除房间')
     for rm in room.roommembers:
         rm.user.joined_room = False
         db.session.delele(rm)
     db.session.delete(room)
     user.joined_room = False
     db.session.coomit()
     return success_msg(msg='房间删除成功!')
Example #9
0
 def put(self):
     '修改用户信息(除密码)'
     user = g.user
     data = request.get_json(force=True)
     # if data.get('username'):
     #     username = data.get('username')
     #     if User.query.filter(User.username == username, User.id != g.user.id).all():
     #         return fail_msg(msg='该用户名已存在!')
     #     user.username = username
     user.birthday = data.get('birthday') if data.get(
         'birthday') else user.birthday
     user.individuality = data.get('individuality') if data.get(
         'individuality') else user.individuality
     user.gender = data.get('gender') if data.get('gender') else user.gender
     user.icon = data.get('icon') if data.get('icon') else user.icon
     db.session.commit()
     return success_msg()
Example #10
0
 def post(self):
     if g.user.joined_room:
         return fail_msg('你已经在一个房间了')
     request_data = request.get_json(force=True)
     room_id = request_data.get('room_id')
     room_password = request_data.get('room_password')
     if not room_id or not room_password:
         return fail_msg('房间号和密码不能为空!')
     room = Room.query.filter_by(id=room_id).first()
     if not room:
         return fail_msg('房间不存在!')
     if room.room_password != room_password:
         return fail_msg('密码错误!')
     if room.count >= room.room_size:
         return fail_msg('房间已满')
     room.count = room.count + 1
     g.user.joined_room = True
     db.session.add(RoomMember(room_id=room.id, user_id=g.user.id))
     db.session.commit()
     return success_msg(msg='房间加入成功', data={'room_id': room.id})
Example #11
0
 def put(self):
     '修改房间信息'
     data = request.get_json(force=True)
     user = g.user
     if not user.joined_room:
         return fail_msg('未加入任何一个房间!')
     room = user.roommenber[0].room
     room.notice = data.get('notice') if data.get('notice') else room.notice
     is_owner = room.owner_id == user.id
     if is_owner:
         room.room_name = data.get('room_name') if data.get(
             'room_name') else room.room_name
         room.room_password = data.get('room_password') if data.get(
             'room_password') else room.room_password
         if data.get('room_size'):
             if int(room.room_size) <= int(data.get('room_size')):
                 room.room_size = data.get('room_size')
         return success_msg(msg='修改成功')
     elif (data.get('room_name') or data.get('room_password')
           or data.get('room_size')):
         return fail_msg('非创建者不能修改重要信息')
Example #12
0
 def post(self):
     '新建房间'
     if g.user.joined_room:
         return fail_msg('你已经在一个房间了')
     request_data = request.get_json(force=True)
     room_name = request_data.get('room_name')
     room_size = request_data.get('room_size')
     room_password = request_data.get('room_password')
     if not room_name or not room_password:
         return fail_msg('房间名或房间密码不能为空')
     if not room_size:
         return fail_msg('请选择房间大小')
     room = Room(owner_id=g.user.id,
                 room_name=str(room_name),
                 room_password=room_password,
                 room_size=room_size)
     g.user.joined_room = True
     db.session.add(room)
     db.session.commit()
     db.session.add(RoomMember(room_id=room.id, user_id=g.user.id))
     db.session.commit()
     return success_msg(msg='房间建立成功', data={'room_id': room.id})