def user_update(id): user = User.query.get(id) username = request.json['username'] email = request.json['email'] user.email = email user.username = username db.session.commit() return user_schema.jsonify(user)
def register(): name = request.json['username'] email = request.json['email'] password = request.json['password'] new_user = User(name, email, password) try: db.session.add(new_user) db.session.commit() except: return 'Username or Email was registed!' return user_schema.jsonify(new_user)
def login(): name = request.json['username'] password = request.json['password'] user = User.query.filter_by(user_name=name).first() if not user: return "This account have been not registed!!" if user.is_deleted: return 'This user was delete, please contact the admin!' if user.user_password == password: return user_schema.jsonify(user) return 'Wrong password!'
def user_delete(id): user = User.query.get(id) db.session.delete(user) db.session.commit() return user_schema.jsonify(user)
def user_detail(id): user = User.query.get(id) return user_schema.jsonify(user)