def editprofile(): print('editprofile entered') user = User() if request.method == 'POST': print('inside editprofile') user.update_profile_details(request.form) print('end of edit profile') return redirect(url_for("profile")) if request.method == 'GET': data = user.get_userDetails(session['email']) if data: firstname = data[0][0] print(firstname) lastname = data[0][1] gender = data[0][2] phone = data[0][3] university = data[0][4] branch = data[0][5] isSmoking = data[0][6] isVegetarian = data[0][7] isAlcoholic = data[0][8] print('GET entered') return render_template('profile-edit.html', firstname=firstname, lastname=lastname, phone=phone, university=university, branch=branch) print('No Get No Post') return render_template('profile-edit.html')
def login(): if request.method == 'POST': user = User() print('I am from Login') if 1 == user.is_already_user(request.form): session['logged_in'] = True session['email'] = request.form['email'] print('user authenticated') return redirect(url_for("home")) elif 2 == user.is_already_user(request.form): error = "Invalid Password" return render_template("login.html", error=error) elif 3 == user.is_already_user(request.form): error = "User does not exist" return render_template("login.html", error=error) return render_template('login.html')
def __init__(self): self.user = User() self.myTickets = MyTickets() self.cinema = Cinema() self.film = Film() self.time = Time() self.place = Place() self.db = DB()
def api_login(): userDb = User(MONGO.db) # 初始化 folderDb = Folder(MONGO.db) name = request.json['name'] password = request.json['password'] user = userDb.find_user(name) if user: if bcrypt.check_password_hash(user['password'], password): resp = get_json_response(app, data=user, message="登陆成功") session['uid'] = str(user["_id"]) folderDb.initfolders(session['uid']) return resp else: return jsonify({"code": -1, "message": "用户名或密码错误"}) else: return jsonify({"code": -1, "message": "用户不存在"})
def api_register(): userDb = User(MONGO.db) name = request.json['name'] email = request.json['email'] password = request.json['password'] pw_hash = bcrypt.generate_password_hash(password).decode('utf-8') user = userDb.find_user(name) if user: return jsonify({"code": -1, "message": "该用户已经注册过了"}) else: data = {'name': name, "email": email, 'password': pw_hash} user = userDb.createUser(data) if user: # ObjectId('5a75c691e566330f9a86a052') is not JSON serializable不能序列化是个问题啊 resp = get_json_response(app, data=user, message="注册成功") return resp else: return jsonify({"code": -1, "message": "注册失败"})
def profile(): if request.method == 'GET': user = User() email = session['email'] data = user.get_userDetails(email) firstname = data[0][0] print(firstname) lastname = data[0][1] gender = data[0][2] phone = data[0][3] university = data[0][4] branch = data[0][5] isSmoking = data[0][6] isVegetarian = data[0][7] isAlcoholic = data[0][8] return render_template('profile.html', firstname=firstname, lastname=lastname, branch=branch, university=university, phone=phone) return render_template('profile.html')
def register(): if request.method == 'POST': user = User() user.parse_user(request.form) reg_result = user.add_user() print('insidePostRegister') if 1 == reg_result: print('User already exists') flash( 'User already exists, please login or try with another email') return render_template("signupStudent.html") elif 3 == reg_result: print('Confirm password does not match with password') flash('Confirm password does not match with password') return render_template("signupStudent.html") elif 2 == reg_result: print('new user added') session['email'] = request.form['email'] return redirect(url_for("editprofile")) if request.method == 'GET': print('InsideGetRegister') return render_template("signupStudent.html")
# from controller.database import Database from controller.user import User from controller.perfil import Perfil from datetime import datetime as Date from bson.objectid import ObjectId user = User() perfil = Perfil() newUser = { 'name': 'Alice', 'password': '******', 'email': '*****@*****.**', 'create_data': Date.now(), 'perfis': [ObjectId("5d52ffed4cd29474379dab54")] } res = user.insertUser(newUser) print(res) users = user.getUsers() for userItem in users: print(userItem['name']) for perfilItem in userItem['perfis']: res = perfil.getPerfil(perfilItem) print(res['name']) print('\n')