Esempio n. 1
0
	def register_user(userinfo):
		user = UserInfo()
		user.user_id = str(uuid.uuid1())
		if userinfo.password :
			user.password = generate_password_hash(userinfo.password.data)
		else :
			user.password = generate_password_hash(DevelopmentConfig.DEFAULT_PASSWORD)
		user.reg_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
		user.email = userinfo.email.data
		user.user_name = userinfo.username.data
		user.nick_name = userinfo.nickname.data
		user.college_name = userinfo.college.data
		user.major_name = userinfo.major.data
		user.grade = userinfo.grade.data
		user.classnum = userinfo.classnum.data
		user.level = '1'
		dbs.session.add(user)
		dbs.session.commit()
Esempio n. 2
0
def register(request):
    if request.method == 'POST':
        form = UserInfoForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            user_exist = User.objects.filter(username=username)
            if user_exist:
                messages.add_message(request, messages.ERROR, "用户名已存在,请更换!")
                return redirect(to='register')
            else:
                user = UserInfo()
                user.username = form.cleaned_data['username']
                user.password = form.cleaned_data['password']
                user.sex = form.cleaned_data['sex']
                user.job = form.cleaned_data['job']
                user.job_num = form.cleaned_data['job_num']
                user.save()
                login(request, user)
                return redirect(to='infomanage')

    elif request.method == 'GET':
        form = UserInfoForm
        return render(request, 'register.html', {'form': form})