def test(): form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data) db.session.add(user) db.session.commit() flash('Done') return render_template('test.html',title='Home',form=form)
def register(request): if request.method == 'POST': Name = request.POST.get('name') Email = request.POST.get('email') Phone = request.POST.get('phone') Homeadd = request.POST.get('homeadd') Carno = request.POST.get('carno') Pw = request.POST.get('pass') user_obj = User() user_obj.name=Name user_obj.email=Email user_obj.phone= Phone user_obj.home_add=Homeadd user_obj.carno= Carno user_obj.password=Pw user_obj.save(force_insert=True) return Response("success")
def getAvgRating(request): number = request.data['rating'] userid = request.data['userid'] rating_user = User.get(Userid=userid) rating_user.number_of_ratings += 1 rating_user.avg_rating = (rating_user.avg_rating * (rating_user.number_of_ratings-1) + number)/ rating_user.number_of_ratings rating_user.save() return HttpResponse("")
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password=bcrypt.generate_password_hash(form.password.data).decode('utf-8') user=User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def reset_token(): if current_user.is_authenticated: return redirect(url_for('home')) user=User.verify_reset_token(token) if user is None: flash('That is an invalid or expired token', 'warning') return redirect(url_for('reset_request')) form=ResetPasswordForm() if form.validate_on_submit(): hashed_password=bcrypt.generate_password_hash(form.password.data).decode('utf-8') user.password=hashed_password db.session.commit() flash('Your password has been updated! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('reset_token.html', title='Reset Password', form=form)
def getAvgRating(request): number = float(request.data['rating']) userid = int(request.data['userid']) rating_user = User() rating_user = User.objects.get(id=userid) if rating_user.number_of_ratings == None: rating_user.number_of_ratings = 0 if rating_user.avg_rating == None: rating_user.avg_rating = "0" avg_rating = float(rating_user.avg_rating) rating_user.number_of_ratings = rating_user.number_of_ratings + 1 avg_rating = (avg_rating * (rating_user.number_of_ratings - 1) + number) / rating_user.number_of_ratings rating_user.avg_rating = str(avg_rating) rating_user.save() print rating_user.avg_rating return HttpResponse("")