Exemplo n.º 1
0
def reg(request, code=''):
	if request.method == 'POST':
		form = RegForm(request.POST)
		if form.is_valid():
			cd = form.cleaned_data
			ck = User.objects.make_random_password(length=26)
			u = UnconfirmedUser(username=cd['username'], email=cd['email'],
				password=cd['password'], confirmation_key=ck,
				expire=datetime.datetime.now() + datetime.timedelta(days=3))
			u.save()
			send_mail('User Confirmation for ' + settings.SITE_NAME, render_to_string('confirmation_email.txt',
				{'key': ck, 'site': settings.SITE_NAME, 'root': settings.SITE_ADDRESS }),
				'*****@*****.**', [cd['email']])
			request.session['email'] = cd['email']
			return HttpResponseRedirect('/success/')
		else:
			return HttpResponse("Your registration form contained validation errors.")
	elif request.method == 'GET':
		if True:	# Registration is open
			form = RegForm()
			return render_to_response(request, 'registration.html', {'form': form})
		elif code:
			try:
				uu = UnconfirmedUser.objects.get(invitation_key=code)
				form = RegForm(initial={'invitation_key': code, 'email': uu.email})
				if form.is_valid():
					return render_to_response(request, 'registration.html', {'form': form})
				return HttpResponseRedirect('/')
			except:
				return HttpResponseRedirect('/')
		else:
			return HttpResponseRedirect('/')
	return HttpResponseRedirect('/')
Exemplo n.º 2
0
def register(request):
    if request.method == 'POST':
        form = RegForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            mobile = form.cleaned_data['mobile']
            team = form.cleaned_data['team']
            email = form.cleaned_data['email']
            problem = form.cleaned_data['problem']
            year = form.cleaned_data['year']
            course = form.cleaned_data['course']
            branch = form.cleaned_data['branch']
            mess = form.cleaned_data['mess']
            roll_no = form.cleaned_data['roll_no']
            tee = form.cleaned_data['tee']
            gender = form.cleaned_data['gender']

            participant = Participant(name=name,mobile=mobile,team=team,email=email,problem=problem,year=year,course=course,
                                      branch=branch,mess=mess,roll_no=roll_no,tee_shirt_size=tee,gender=gender)
            participant.save()

            return render_to_response("hackathon/success.html", RequestContext(request,{'name':name}))
        else:
            return render_to_response("hackathon/register.html", RequestContext(request, {'form' : form}))

    form = RegForm()
    return render(request,'hackathon/register.html',{'form':form})
Exemplo n.º 3
0
def do_reg(request):
    try:
        if request.method == 'POST':
            print "POST do_reg"
            reg_form = RegForm(request.POST)
            if reg_form.is_valid():
                # 注册
                user = UserProfile.objects.create(
                                    email=reg_form.cleaned_data["email"],
                                    password=make_password(reg_form.cleaned_data["password"]),
                                    reg_ip=get_client_ip(request))
                user.save()

                # 登录
                print "OK reg_form"
                print reg_form.cleaned_data["email"], reg_form.cleaned_data["password"]
                user = authenticate(username=reg_form.cleaned_data["email"], password=reg_form.cleaned_data["password"])
                login(request, user)
                return redirect("/index/")
            else:
                return render(request, 'failure.html', {'reason': reg_form.errors})
        else:
            reg_form = RegForm()
    except Exception as e:
        logger.error(e)
    return render(request, 'reg.html', locals())
Exemplo n.º 4
0
def do_reg(request):
    try:
        if request.method == 'POST':
            reg_form = RegForm(request.POST)
            if reg_form.is_valid():
                # 注册
                from django.contrib.auth.hashers import make_password
                user = User.objects.create(username=reg_form.cleaned_data["username"],
                                           email=reg_form.cleaned_data["email"],
                                           url=reg_form.cleaned_data["url"],
                                           password=make_password(reg_form.cleaned_data["password"]), )
                user.save()

                # 登录
                # 指定默认的登录验证方式
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                login(request, user)
                return redirect(request.POST.get('source_url'))
            else:
                return render(request, 'failure.html', {'reason': reg_form.errors})
        else:
            reg_form = RegForm()
    except Exception as e:
        logger.error(e)
    return render(request, 'reg.html', locals())
Exemplo n.º 5
0
def do_reg(request):
    try:
        if request.method == 'POST':
            reg_form = RegForm(request.POST)
            if reg_form.is_valid():
                # 注册
                from django.contrib.auth.hashers import make_password
                user = User.objects.create(
                    username=reg_form.cleaned_data["username"],
                    email=reg_form.cleaned_data["email"],
                    url=reg_form.cleaned_data["url"],
                    password=make_password(reg_form.cleaned_data["password"]),
                )
                user.save()

                # 登录
                # 指定默认的登录验证方式
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                login(request, user)
                return redirect(request.POST.get('source_url'))
            else:
                return render(request, 'failure.html',
                              {'reason': reg_form.errors})
        else:
            reg_form = RegForm()
    except Exception as e:
        logger.error(e)
    return render(request, 'reg.html', locals())
Exemplo n.º 6
0
def register(request):
    if request.method == 'POST':
        form = RegForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            mobile = form.cleaned_data['mobile']
            team = form.cleaned_data['team']
            email = form.cleaned_data['email']
            problem = form.cleaned_data['problem']
            year = form.cleaned_data['year']
            course = form.cleaned_data['course']
            branch = form.cleaned_data['branch']
            mess = form.cleaned_data['mess']
            roll_no = form.cleaned_data['roll_no']

            participant = Participant(name=name,
                                      mobile=mobile,
                                      team=team,
                                      email=email,
                                      problem=problem,
                                      year=year,
                                      course=course,
                                      branch=branch,
                                      mess=mess,
                                      roll_no=roll_no)
            participant.save()

            return render_to_response("hackathon/success.html",
                                      RequestContext(request, {'name': name}))
        else:
            return render_to_response("hackathon/register.html",
                                      RequestContext(request, {'form': form}))

    form = RegForm()
    return render(request, 'hackathon/register.html', {'form': form})
Exemplo n.º 7
0
def do_reg(request):
    try:
        if request.method == 'POST':
            if request.POST['password'] != request.POST['password_again']:
                return render(request, 'reg.html', {"reason": u"两次密码不相同"})
            if request.POST['username'] in User.objects.values_list('username', flat=True):
                return render(request, 'reg.html', {"reason": u"用户已存在"})
            reg_form = RegForm(request.POST)
            if reg_form.is_valid():
                # 注册
                user = User.objects.create(username=reg_form.cleaned_data["username"],
                                           email=reg_form.cleaned_data["email"],
                                           url=reg_form.cleaned_data["url"],
                                           password=make_password(reg_form.cleaned_data["password"]),)
                user.save()
                # 登录
                # 指定默认的登录验证方式
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                login(request, user)
                if '/power/login/' in request.POST.get('source_url') or\
                        '/power/reg/' in request.POST.get('source_url'):
                    return redirect('/home/')
                return redirect(request.POST.get('source_url'))
            else:
                return render(request, 'failure.html', {'reason': reg_form.errors})
        else:
            reg_form = RegForm()
    except Exception as e:
        print e
    return render(request, 'reg.html', locals())
Exemplo n.º 8
0
def register_user(request):
    if request.method == 'POST':
        form = RegForm(request.POST)
        if form.is_valid():
            print 'form is valid! here'
            form.save()
            return render(request, 'index.html')
        else:
            print form.errors
    args = {}
    args.update(csrf(request))
    args['form'] = RegForm()
    return render_to_response('register.html', args)
Exemplo n.º 9
0
def register_user(request):
    if request.method == 'POST':
        form = RegForm(request.POST)
        if form.is_valid():
            print 'form is valid! here'
            form.save()
            return render(request,'index.html')
        else:
            print form.errors
    args = {}
    args.update(csrf(request))
    args['form'] = RegForm()
    return render_to_response('register.html',args)
Exemplo n.º 10
0
def reg_form(request):
    flag = 'update'
    try:
        instance = Student.objects.get(email_id=request.user.email)
    except:
        flag = 'new'
        instance = ''
        pass
    if request.method == 'POST':
        if flag == 'update':
            form = RegForm(request.POST or None,
                           request.FILES,
                           instance=instance)
        else:
            form = RegForm(request.POST, request.FILES)
        if form.is_valid():
            first_name = request.POST.get('first_name', '')
            middle_name = request.POST.get('middle_name', '')
            last_name = request.POST.get('last_name', '')
            email_id = request.user.email
            phone_no = request.POST.get('phone_no', '')
            school_name = request.POST.get('school_name', '')
            class_name = request.POST.get('class_name', '')
            avatar = request.FILES.get('avatar', '')
            if flag == 'update':
                instance.first_name = first_name
                instance.last_name = last_name
                instance.middle_name = middle_name
                instance.email_id = email_id
                instance.phone_no = phone_no
                instance.school_name = school_name
                instance.class_name = class_name
                instance.avatar = avatar
                instance.save()
            else:
                obj = Student(first_name=first_name,
                              middle_name=middle_name,
                              last_name=last_name,
                              email_id=email_id,
                              phone_no=phone_no,
                              school_name=school_name,
                              class_name=class_name,
                              avatar=avatar)
                obj.save()
            return info(request)
        else:
            print form.errors
    form = RegForm()
    context = {'form': form, 'student': instance}
    return render(request, 'registration.html', context)
Exemplo n.º 11
0
def reg(request):
	form = RegForm()
	if request.method == 'POST':
		form = RegForm(request.POST)
		if form.is_valid():
			print 'form is valid'
			cd = form.cleaned_data
			u = User.objects.create_user(cd['username'], cd['email'], cd['pw'])
			u.first_name = cd['first_name']
			u.last_name = cd['last_name']
			u.save()
			u = authenticate(username=cd['username'], password=cd['pw'])
			login(request,u)
			return HttpResponseRedirect(reverse('home'))
	return render_to_response('registration.html', {'reg_form': form, 'login_form': LoginForm()}, context_instance=RequestContext(request))
Exemplo n.º 12
0
 def post(self, request):
     regform = RegForm(
         request.POST)  # 通过注册表单获取用户提交的内容(form表单中的name字段),然后创建实例regform
     if regform.is_valid():  # 若表单有效性验证成功
         username = request.POST.get("email", "")  # 获取用户/邮箱/密码信息
         email = request.POST.get("email", "")
         password = request.POST.get("password", "")
         user = User()  # 创建用户实例
         user.username = username  # 为用户名/邮箱/密码数据属性赋值
         user.email = email
         user.password = password
         user.password = make_password(password)  # 将密码加密处理
         user.save()  # 保存到数据库(除了用save,也可以用create方式)
         return render(request, "login.html")  # 验证有效之后,返回登录页面
     else:
         return render(request, "reg.html",
                       {"regform": regform})  # 如果表单验证失败,则停留在注册页面
Exemplo n.º 13
0
 def post(self, request):
     regform = RegForm(request.POST)  # 通过注册表单获取用户的POST信息
     if regform.is_valid():  # 若表单认证成功
         # 获取用户信息
         # username = request.POST.get("username", "")
         email = request.POST.get("email", "")
         password = request.POST.get("password", "")
         user = User()  # user模板实例
         # user.username = username
         user.email = email
         user.password = password
         user.password = make_password(password)
         user.save()  # 保存数据库
         return render(request, "login.html")  # 验证有效之后,返回登录页面
     else:
         return render(request, "reg.html",
                       {"regform": regform})  # 验证失败,停留在注册页面
Exemplo n.º 14
0
def register(req):
    if req.method == 'POST':
        uf = RegForm(req.POST)
        if uf.is_valid():
            #获得表单数据
            username = uf.cleaned_data['username']
            pwd = uf.cleaned_data['pwd']
            #添加到数据库
            user = User.objects.create(username=username, pwd=pwd)
            req.session['user'] = user.username
            return render(req, 'register.html', {'uf': uf, 'success': True})
    else:
        uf = RegForm()
    return render(
        req,
        'register.html',
        {'uf': uf},
    )
Exemplo n.º 15
0
def reg(request):
    form = RegForm()
    if request.method == 'POST':
        form = RegForm(request.POST)
        if form.is_valid():
            print 'form is valid'
            cd = form.cleaned_data
            u = User.objects.create_user(cd['username'], cd['email'], cd['pw'])
            u.first_name = cd['first_name']
            u.last_name = cd['last_name']
            u.save()
            u = authenticate(username=cd['username'], password=cd['pw'])
            login(request, u)
            return HttpResponseRedirect(reverse('home'))
    return render_to_response('registration.html', {
        'reg_form': form,
        'login_form': LoginForm()
    },
                              context_instance=RequestContext(request))
Exemplo n.º 16
0
def register(request):
    if request.user.is_authenticated():
        return post_item(request)
    user = None
    signinform = SignInForm()
    if request.method == 'POST':
        form = RegForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['email'].find('@sjsu.edu')!=-1:
                user = User(
                    first_name=form.cleaned_data['firstname'],
                    last_name=form.cleaned_data['lastname'],
                    email=form.cleaned_data['email'],
                    username=form.cleaned_data['email']
                )
                user.set_password(form.cleaned_data['password1'])
                try:
                    user.save()
                except IntegrityError:
                    form.addError(user.email + ' is already a member')
                else:
                    user = authenticate(username=form.cleaned_data['email'],
                                        password=form.cleaned_data['password1'])
                    if user is not None:
                        if user.is_active:
                            login(request, user)
                    return HttpResponseRedirect('/')
            else:
                form.addError("You did Not enter a valid email address")
    else:
        form = RegForm()
    return render_to_response(
        'register.html',
        {
        'form': form,
        'signinform': signinform,
        'months': range(1, 12),
        'user': request.user,
        },
        context_instance=RequestContext(request)
    )
Exemplo n.º 17
0
def reg_form(request):
    flag='update'
    try:
        instance = Student.objects.get(email_id=request.user.email)
    except:
        flag='new'
        instance=''
        pass
    if request.method == 'POST':
        if flag=='update':
            form = RegForm(request.POST or None,request.FILES,instance=instance)
        else:
            form = RegForm(request.POST,request.FILES)
        if form.is_valid():
            first_name=request.POST.get('first_name','')
            middle_name=request.POST.get('middle_name','')
            last_name=request.POST.get('last_name','')
            email_id=request.user.email
            phone_no=request.POST.get('phone_no','')
            school_name=request.POST.get('school_name','')
            class_name=request.POST.get('class_name','')
            avatar = request.FILES.get('avatar','')
            if flag=='update':
                instance.first_name=first_name
                instance.last_name=last_name
                instance.middle_name=middle_name
                instance.email_id=email_id
                instance.phone_no=phone_no
                instance.school_name=school_name
                instance.class_name=class_name
                instance.avatar=avatar
                instance.save()
            else:
                obj = Student(first_name=first_name,middle_name=middle_name,last_name=last_name, email_id=email_id, phone_no=phone_no,school_name=school_name,class_name=class_name,avatar=avatar)
                obj.save()
            return info(request)
        else:
            print form.errors
    form = RegForm()
    context={'form': form,'student':instance}
    return render(request,'registration.html',context)
Exemplo n.º 18
0
def register(request):
	if request.user.is_active:
		return HttpResponseRedirect(reverse('rango:userdetails'))
	template_name='rango/register.html'
	user=UserForm()
	form=RegForm()
	if request.method=='POST':
		form = RegForm(request.POST, request.FILES)
		user = UserForm(request.POST)
		if user.is_valid() and form.is_valid():
			u=user.save()
			u.set_password(request.POST['password'])
			u.save()
			a=form.save(commit=False)
			a.picture=request.FILES['picture']
			a.user=u
			a.save()
			return HttpResponseRedirect(reverse('rango:login'))
		else:
			return render(request, template_name, {'form':[form,user]})
	else:
		return render(request, template_name, {'form':[form,user]})
Exemplo n.º 19
0
def register(request):
    if request.user.is_authenticated():
        return post_item(request)
    user = None
    signinform = SignInForm()
    if request.method == 'POST':
        form = RegForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['email'].find('@sjsu.edu') != -1:
                user = User(first_name=form.cleaned_data['firstname'],
                            last_name=form.cleaned_data['lastname'],
                            email=form.cleaned_data['email'],
                            username=form.cleaned_data['email'])
                user.set_password(form.cleaned_data['password1'])
                try:
                    user.save()
                except IntegrityError:
                    form.addError(user.email + ' is already a member')
                else:
                    user = authenticate(
                        username=form.cleaned_data['email'],
                        password=form.cleaned_data['password1'])
                    if user is not None:
                        if user.is_active:
                            login(request, user)
                    return HttpResponseRedirect('/')
            else:
                form.addError("You did Not enter a valid email address")
    else:
        form = RegForm()
    return render_to_response('register.html', {
        'form': form,
        'signinform': signinform,
        'months': range(1, 12),
        'user': request.user,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 20
0
        return render(request, 'hackathon/index.html', context)
    sponsors = sponsors.filter(hackathon=hackathon)
    context = {'hackathon':hackathon, 'sponsors':sponsors}
    return render(request, 'hackathon/index.html', context)

def register(request):
    try:
        hackathon = Hackathon.objects.all().filter(is_active=True)[0]
    except Exception, e:
        hackathon = None;
    if hackathon is None:
        return render_to_response('hackathon/register.html', RequestContext(request, {'finished':'True'}))

    if request.method == 'POST' and request.user.is_authenticated():
        form = RegForm(request.POST)
        if form.is_valid():
            user = request.user
            mobile = form.cleaned_data['mobile']
            team = form.cleaned_data['team']
            problem = form.cleaned_data['problem']
            year = form.cleaned_data['year']
            course = form.cleaned_data['course']
            branch = form.cleaned_data['branch']
            mess = form.cleaned_data['mess']
            roll_no = form.cleaned_data['roll_no']
            tee = form.cleaned_data['tee']
            gender = form.cleaned_data['gender']

            participant = Participant(name=name, mobile=mobile, team=team, email=email, problem=problem, year=year, course=course,
                                      branch=branch, mess=mess, roll_no=roll_no, tee_shirt_size=tee, gender=gender, hackathon=hackathon)