コード例 #1
0
ファイル: views.py プロジェクト: 206473/python-lab
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 login(request):
    """显示登录界面"""
    if request.method == 'POST':
        u = User()
        u.user_name = request.POST.get('username')
        u.user_password = request.POST.get('password')
        print(u.user_name, u.user_password)
        return redirect("/today/")
    else:
        return render(request, 'index/login.html')
コード例 #4
0
ファイル: app.py プロジェクト: swpu-cxm/login
def confirm(confirm_url):
    """
    通过动态url获取用户验证的加密口令,若口令错误,则解码失败,解码成功后将用户信息添加进数据库中
    :param confirm_url:
    :return:
    """
    try:
        msg = decode_msg(confirm_url)
        user = User(username=msg['username'],
                    mail=msg['mail'],
                    password=msg['password_hash'])
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login'))
    except Exception as e:
        return render_template('404.html'), 404
コード例 #5
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')
コード例 #6
0
ファイル: views.py プロジェクト: Cyz-C/MissionOffer
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
コード例 #7
0
ファイル: views.py プロジェクト: zhaojinweipay/MissionOffer
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