示例#1
0
文件: views.py 项目: sunsaijie/fruit
def register_view(request):
    if request.method == "GET":
        return render(request, "register.html")
    else:
        # 实现注册的功能
        uphone = request.POST["uphone"]
        upwd = request.POST['upwd']
        uname = request.POST["uname"]
        uemail = request.POST['email']

        dict = {
            "uphone": uphone,
            "upwd": upwd,
            "uname": uname,
            "uemail": uemail
        }

        # 保存进数据库
        users = User(**dict).save()

        u = User.objects.get(uphone=uphone)

        # 将用户id和uphone保存进session

        request.session['uid'] = u.id
        request.session['uphone'] = u.uphone

        return redirect("/")
示例#2
0
def CreateAdminUser(request, Data):
    # もし、メールアドレスが既に登録されていたらエラーを返す
    if User.objects.filter(email=Data['email']):
        url = ''
    else:
        # ここで新規登録処理
        now = datetime.datetime.now()
        UserData = User(
            name=Data['name'],
            email=Data['email'],
            password=sha1(Data['password'].encode('utf-8')).hexdigest(),
        )
        UserData.save()
        user = User.objects.all().filter(name=Data['name']).first()
        request.session['user_id'] = user.id
        url = '/'

    return url
示例#3
0
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, please login', 'success')
		return redirect(url_for('login'))
	return render_template('register.html', title='Register', form=form)
示例#4
0
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(firstname = form.firstname.data, lastname = form.lastname.data, college = form.college.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        name = form.firstname.data
        s    = 'Account created for ' + name + ' successfully !'
        flash(s,'success')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
示例#5
0
def add_user(request):
    form = UserAddForm(request.POST or None)
    if form.is_valid():
        user = User()
        account = form.save(commit=False)
        password = form.cleaned_data.get('password')
        password_ = form.cleaned_data.get('password_')
        username = form.cleaned_data.get('username')
        if account.employee:
            employee = Account.objects.filter(employee=account.employee)
            if employee.count() >= 1:
                messages.error(request, "Employee already exist")
                return redirect('/users/add/')

        if username:
            user_name = User.objects.filter(username=username)
            if user_name:
                messages.error(request, "Username already exist")
                return redirect('/users/add/')
        if password != password_:
            messages.error(request, "Passwords does not match")
            return redirect('/users/add/')
        if len(password) <= 5:
            messages.error(request,
                           "Passwords must contain at least 6 characters")
            return redirect('/users/add/')
        if (account.employee.level == 'Cleaner') | (account.employee.level
                                                    == 'Other'):
            messages.error(
                request, "This emplyee can't use the system\nCleaner or other")
            return redirect('/users/add')
        user.first_name = form.cleaned_data.get('first_name')
        user.last_name = form.cleaned_data.get('last_name')
        user.username = username
        user.set_password(password)
        user.save()
        account.user = user
        account.save()
        return redirect('/users/')
    context = {'form': form}
    return render(request, 'add_user.html', context)
示例#6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():

        hash_pass = bcrypt.generate_password_hash(
            form.password.data).decode('utf8')

        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hash_pass)

        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.username.data}.', category='success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
示例#7
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('Invalid or expired Token!', 'warning')
        return redirect(url_for('users.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(f'your pw has been updated', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
示例#8
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_password_token(token)
    if not user:
        flash('This token is invalid. Please enter your email again.',
              category='warning')
        return redirect(url_for('users.reset_password_request'))
    else:
        form = ResetPasswordForm()
        if form.validate_on_submit():
            hashed_password = bcrypt.generate_password_hash(form.password.data)
            user.password = hashed_password
            db.session.commit()
            flash('Your password has been updated.', category='success')
            return redirect(url_for('users.login'))
        return render_template('reset_password.html',
                               title='Reset Password',
                               form=form)
示例#9
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('afterlogin'))
    form = Signup()
    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,
                    age=form.age.data,
                    city=form.city.data,
                    phone=form.phone.data,
                    faculty_name=str(form.Faculty_name),
                    gender=form.gender.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login'))

    return render_template('signup.html', form=form, legend='Sign up')
示例#10
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        #Hashing the password using bcrypt
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')

        #Creating the user using the from and insert into the database
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()

        flash(f'Account created! Now log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
示例#11
0
文件: views.py 项目: leeyy216/bysj
def register(request):
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #获取表单信息
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            email = uf.cleaned_data['email']
            #将表单写入数据库
            user = User()
            user.username = username
            user.password = password
            user.email = email
            user.save()
            #返回注册成功页面
            return render(request, 'success.html', {'username': username})
    else:
        uf = UserForm()
        return render(request, 'register.html', {'uf': uf})
    #return render(request, 'register.html')
示例#12
0
    def post(self, request, *args, **kwargs):
        # 获取用户提交的数据
        # session:request.session.get('')
        user = request.data.get('username')
        """
        def query_params(self):

            #More semantically correct name for request.GET.

            return self._request.GET
            相当于:user=request._request.GET('username')
        """
        pwd = request.data.get('password')
        # 实例化用户表
        userinfo = User()
        userinfo.username = user
        userinfo.pwd = pwd
        userinfo.save()
        return Response({'code': 200, 'successful': '注册成功'})
示例#13
0
def index(request):
    #
    photos = Photo.objects.all().order_by('position')
    files = Upload.objects.all().order_by('filename')
    # file_types = Upload.objects.all().order_by('file_type')
    # if request.method == 'GET':
    inputMail = request.GET.get('email', '')
    print(inputMail)
    ##验证邮箱的合法性
    isMatch = bool(
        re.match(
            r"^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$",
            inputMail, re.VERBOSE))
    #print(isMatch)
    if isMatch:
        ##邮箱去重
        is_email_exist = User.objects.filter(email=inputMail).exists()
        if is_email_exist:
            # ret=0
            # return HttpResponse(json.dumps({
            #     "ret": ret,
            # }))
            status = send_email(inputMail)
            if status:
                print("邮件发送成功")

        else:
            ##实例化用户表
            user_profile = User()
            user_profile.email = inputMail
            user_profile.is_activate = False
            user_profile.save()
            ##发送邮件
            #status = send_email(inputMail)
            #mess="订阅成功,我们将给你邮箱发送激活链接,注意查收"
            status = send_email(inputMail)
            if status:
                print("邮件发送成功")
    # else:
    #     mess = "邮箱格式不正确"
    return render(request, 'index.html', locals())