示例#1
0
def index(request):
    c = {}
    if request.method == 'POST':
        logins = request.POST.get('login')
        passwords = request.POST.get('password')
        emails = request.POST.get('email')

        try:
            conn = psycopg2.connect(
                "dbname='laba' user='******' host='localhost' password='******' port='5432'"
            )
        except:
            print("I am unable to connect to the database")
        else:
            try:
                try:
                    user = User.objects.get(login=logins, email=emails)
                    return HttpResponse('Пользователь уже существует!')
                except:
                    user = User(login=logins, password=passwords, email=emails)
                    user.save()
                    return redirect('/')
            except:
                #user=1
                return HttpResponse("Error!")
    else:
        return render_to_response('register.html', {},
                                  context_instance=RequestContext(request))
示例#2
0
def index(request):
	c = {}
	if request.method == 'POST':
		logins = request.POST.get('login')
		passwords = request.POST.get('password')
		emails = request.POST.get('email')
		
		try:
			conn = psycopg2.connect("dbname='laba' user='******' host='localhost' password='******' port='5432'")
		except:
			print("I am unable to connect to the database")
		else:
			try:
				try:
					user = User.objects.get(login=logins, email=emails)
					return HttpResponse('Пользователь уже существует!')
				except:
					user = User(login=logins, password=passwords, email=emails);
					user.save()
					return redirect('/');
			except:
				#user=1
				return HttpResponse("Error!")
	else:
		return render_to_response('register.html',{},context_instance=RequestContext(request))
示例#3
0
def register(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        u = User()
        u.user_name = username
        u.user_password = password
        u.save()
        u_id = u.id
        return JsonResponse({'res': '1', 'uid': u_id})
    return render(request, 'index/register.html')
示例#4
0
def createNewUser(post):

    newUser = User()  # 创建新用户,加入到数据库中。
    newUser.usrname = post['nickname']
    newUser.password = post['password']
    newUser.idNumber = post['student_number']
    newUser.email = post['usrname']
    newUser.sex = post['sex']
    newUser.phonenumber = post['phone_number']
    newUser.eval = post['introduce']
    newUser.authKey = hashlib.sha1(str(random()).encode('utf-8')).hexdigest()
    newUser.isActive = False

    # emailContent = loader.render_to_string('Email.html')
    # print(emailContent)
    subject = 'MissionOffer register e-mail'
    fromEmail = '*****@*****.**'
    toEmail = [newUser.email]
    t = loader.get_template('Email.html')
    activateUrl = MY_SITE_URL+'/register/activate/'+newUser.authKey
    htmlContent = t.render(Context({'activateUrl':activateUrl}))
    msg = EmailMultiAlternatives(subject, htmlContent, fromEmail, toEmail)
    msg.attach_alternative(htmlContent, "text/html")
    try :
        msg.send()
    except:
        print ('Email Error')
        return None
    newUser.save()
    # send_mail('MissionOffer register e-mail',
    #           emailContent,
    #           #'This is a test e-mail from MissionOffer website.',
    #           # 'http://192.168.1.115:8000/register/emailAuth/'
    #           # +newUser.authKey,
    #           '*****@*****.**',
    #           [newUser.email],
    #           fail_silently=False)
    return newUser
示例#5
0
def createNewUser(post):

    newUser = User()  # 创建新用户,加入到数据库中。
    newUser.usrname = post['nickname']
    newUser.password = post['password']
    newUser.idNumber = post['student_number']
    newUser.email = post['usrname']
    newUser.sex = post['sex']
    newUser.phonenumber = post['phone_number']
    newUser.eval = post['introduce']
    newUser.authKey = hashlib.sha1(str(random()).encode('utf-8')).hexdigest()
    newUser.isActive = False

    # emailContent = loader.render_to_string('Email.html')
    # print(emailContent)
    subject = 'MissionOffer register e-mail'
    fromEmail = '*****@*****.**'
    toEmail = [newUser.email]
    t = loader.get_template('Email.html')
    activateUrl = MY_SITE_URL + '/register/activate/' + newUser.authKey
    htmlContent = t.render(Context({'activateUrl': activateUrl}))
    msg = EmailMultiAlternatives(subject, htmlContent, fromEmail, toEmail)
    msg.attach_alternative(htmlContent, "text/html")
    try:
        msg.send()
    except:
        print('Email Error')
        return None
    newUser.save()
    # send_mail('MissionOffer register e-mail',
    #           emailContent,
    #           #'This is a test e-mail from MissionOffer website.',
    #           # 'http://192.168.1.115:8000/register/emailAuth/'
    #           # +newUser.authKey,
    #           '*****@*****.**',
    #           [newUser.email],
    #           fail_silently=False)
    return newUser