def register(): form = RegisterForm() org = Organisation.query.filter_by(id= session['organisation_id']).first() if form.validate_on_submit(): try: salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) user= User(firstname= form.firstname.data, lastname= form.lastname.data, email= form.email.data, username= form.username.data, password= hashed_password, organisation= org, is_admin= form.is_admin.data, is_active= form.is_active.data) # token = generate_confirmation_token(user.email) # confirm_url = url_for('confirm_account', token=token, _external=True) # html = render_template('users/activate.html', confirm_url=confirm_url) # subject = "Please confirm your email" db.session.add(user) db.session.commit() # send_email(user.email, subject, html) #flash('A confirmation email has been sent via email.', 'alert-success') flash('User Registered Successfully ', 'alert-success') return redirect(url_for('newuserprojectassignment')) except exc.IntegrityError: flash('The user details conflict with existing user', 'alert-danger') db.session.rollback() return redirect(url_for('view_users')) return render_template('users/register.html', form=form, action='new')
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get("email", "") if UserProfile.objects.filter(email=user_name): return render(request, 'register.html', { 'msg': '用户已存在', 'register_form': register_form }) pass_word = request.POST.get("password", "") user_profile = UserProfile() user_profile.username = user_name user_profile.email = user_name #这样注册可以用邮箱也可以用用户名作为账户 user_profile.password = make_password(pass_word) user_profile.is_active = False user_profile.save() #写入欢迎注册消息 user_message = UserMessage() user_message.user = user_profile.id user_message.message = '注册成功,欢迎加入' user_message.save() send_register_email(user_name, 'register') return render(request, 'login.html') else: return render(request, 'register.html', {'register_form': register_form})
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get("email", '') if UserProfile.objects.filter(email=user_name): return render(request, 'register.html', { "register_form": register_form, "msg": "用户已经存在" }) pass_word = request.POST.get('password', '') user_profile = UserProfile() user_profile.username = str(user_name) user_profile.email = user_name, user_profile.is_active = False user_profile.password = make_password(pass_word) user_profile.save() user_message = UserMessage() user_message.user = user_profile.id user_message.message = "欢迎注册one code在线课堂" user_message.save() send_register_email(user_name, 'register') return render(request, 'login.html') else: return render(request, 'register.html', {"register_form": register_form})
def post(self, request): register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get('email', None) # 如果用户已存在,则提示错误信息 if UserProfile.objects.filter(email=user_name): return render(request, 'register.html', { 'register_form': register_form, 'msg': '用户已存在' }) pass_word = request.POST.get('password', None) # 实例化一个user_profile对象 user_profile = UserProfile() user_profile.username = user_name user_profile.email = user_name user_profile.is_active = False # 对保存到数据库的密码加密 user_profile.password = make_password(pass_word) user_profile.save() send_register_eamil(user_name, 'register') return render(request, 'login.html') else: return render(request, 'register.html', {'register_form': register_form})
def RegisterView(request): if request.method == 'GET': register_form = RegisterForm() return render(request, 'user/register.html', {'register_form': register_form}) if request.method == 'POST': form_obj = RegisterForm(request.POST) if form_obj.is_valid(): # 如果通过基本验证 则发送短信 code = random.randint(1000, 10000) if code: # 短信发送正常 form_obj.cleaned_data['username'] = form_obj.cleaned_data[ 'phone'] user = User.add_new_user(form_obj.cleaned_data) PhoneCode.objects.create(code=code, user=user) message = '短信发送成功' messages.success(request, message) return redirect( reverse('users:register_code', kwargs={'uuid': user.uuid})) else: # 短信发送失败 message = '短信发送失败' messages.error(request, message) return render(request, 'user/register.html', {'register_form': form_obj}) return redirect(reverse('users:login')) else: return render(request, 'user/register.html', {'register_form': form_obj})
def register(): form = RegisterForm() if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) user = User(name=form.name.data, password=hashed_password) db.session.add(user) db.session.commit() return redirect(url_for('list')) return render_template('users/register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) db.create_all() user = User(form.fullname.data, form.email.data, form.username.data, hashed_password) db.session.add(user) db.session.commit() return redirect(url_for('success')) return render_template('users/register.html', form=form)
def register(): if current_user.is_authenticated : return redirect(url_for('home')) form=RegisterForm() if form.validate_on_submit() : hash_password=bcrypt.generate_password_hash(form.password.data).decode("utf-8") user=User(username=form.username.data,email=form.email.data,password=hash_password) db.session.add(user) db.session.commit() flash(f"'{form.username} is created you can login now ","success") return redirect(url_for('user.login')) return render_template("user/register.html",title="Register",form=form)
def register(request): redirect_to = request.POST.get('next', request.GET.get('next', '')) if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): form.save() if redirect_to: return redirect(redirect_to) else: return redirect('/') else: form = RegisterForm() return render(request, 'users/register.html', context={'form': form, 'next': redirect_to})
def register(): form = RegisterForm() if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) user = User(form.firstname.data, form.lastname.data, form.email.data, form.username.data, hashed_password, True) db.session.add(user) db.session.commit() flash('User Registered') return redirect(url_for('login_success')) return render_template('users/register.html', form=form)
def edit_user(id): if session.get('is_admin') or id==str(session['user_id']): user = User.query.filter_by(id=id).first() form = RegisterForm(obj= user) org = Organisation.query.filter_by(id= session['organisation_id']).first() if request.method=='POST': try: salt = bcrypt.gensalt() user.firstname= form.firstname.data user.lastname= form.lastname.data user.email= form.email.data user.organisation= org user.is_admin= form.is_admin.data user.is_active = form.is_active.data db.session.flush() db.session.commit() flash('User Details Successfully Updated', 'alert-success') return redirect(url_for('login_success')) except : flash('Unexpected error have occurred while saving your data. Contact system admin', 'alert-danger') db.session.rollback() return redirect(url_for('view_users')) return render_template('users/register.html', form = form, user=user, action='edit') else: flash ("You don't have enough permissions to perform changes to user details", 'alert-danger') return redirect(url_for('login_success'))
def register(): form = RegisterForm() if form.validate_on_submit(): salt = bcrypt.gensalt() hashed_password = bcrypt.hashpw(form.password.data, salt) db.create_all() user = User( form.fullname.data, form.email.data, form.username.data, hashed_password ) db.session.add(user) db.session.commit() return redirect(url_for('success')) return render_template('users/register.html', form=form)
def LoginView(request): if request.method == 'GET': register_form = RegisterForm() return render(request, 'user/login.html', {'register_form': register_form}) if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): user = authenticate( username=form.cleaned_data["username"], password=form.cleaned_data["password"], ) if user and user.is_active: login(request, user) messages.success(request, "自动跳转到主页", extra_tags="登录成功!") return HttpResponseRedirect(reverse("sspanel:userinfo"))
def register(request): redirect_to = request.POST.get('next', request.GET.get('next', '')) if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): form.save() if redirect_to: return redirect(redirect_to) else: return redirect('/') else: form = RegisterForm() return render(request, 'users/register.html', context={ 'form': form, 'next': redirect_to })
def get(self, request): register_form = RegisterForm() return render(request, 'register.html', {'register_form': register_form})
def get(self, request): register_form = RegisterForm() return render(request, 'register.html', locals())