Esempio n. 1
0
def logon(request):
    # print(request.POST)
    if ('username' in request.POST) and ('email' in request.POST) and (
            'code' in request.POST) and ('password' in request.POST):
        username = request.POST['username']
        if not (User.objects.filter(username=username).exists()):
            email = request.POST['email']
            code = request.POST['code']
            password = request.POST['password']
            if str(gen_code(email)) == str(code):
                user = User()
                user.username = username
                user.password = make_password(password)
                user.email = email
                user.contact = "4008823823"
                user.identity = "normal"
                user.apply = "False"
                user.token = ""
                user.save()
                add_dialog('第{}用户{}完成注册,注册邮箱是{}'.format(
                    user.id, username, email))
                return JsonResponse({"state": 1})
            else:
                return JsonResponse({"state": "注册失败code is error"})
        return JsonResponse({"state": "注册失败username is exist"})
    return JsonResponse({"state": "注册失败变量不够"})
Esempio n. 2
0
def login_result(request): # 登陆的结果
    password =  request.POST['password']
    if password=='':
        return HttpResponse('登陆失败!请填写密码')
    email =  request.POST['email']
    if email=='':
        return HttpResponse('登陆失败!请填写邮箱')
    u=User()
    u.email=email
    u.password=password
    try:
       user=User.objects.get(email=email) # user是指从数据库里面查找的邮箱为email的用户
    except User.DoesNotExist:
        return HttpResponse("账户不存在")
    if user.password==hashlib.sha1(u.password).hexdigest(): # u是登陆之时填写的用户
        result=get_template('login_result.html') # 比较数据库的用户的密码和填写的密码是否一致
        resultHtml=result.render(Context())
        request.session['user']=user
        return HttpResponse(resultHtml)
    else:
        return HttpResponse("密码错误")
Esempio n. 3
0
def reg_result(request): # 注册的结果页面
    password =  request.POST['password'] #从表单里拿到密码
    if password=='': # 没填密码
        return HttpResponse('注册失败!请填写密码')
    email =  request.POST['email']
    if email=='':# 没填邮箱
        return HttpResponse('注册失败!请填写邮箱')
    realname =  request.POST['realname']
    if realname=='':
        return HttpResponse('注册失败!请填写真实姓名')
    invitecode =  request.POST['invitecode']
    if invitecode=='':
        return HttpResponse('注册失败!请填写邀请码')
    u=User() # 新建一个User对象,把它存入数据库
    u.email=email
    u.password=hashlib.sha1(password).hexdigest() # 这是生成hash值代替明文的密码
    u.name=realname
    u.sec=Section.objects.get(id=1)
    u.save()
    request.session['user']=u # 把user对象放到session里面去
    result=get_template('result.html')
    resultHtml=result.render(Context())
    return HttpResponse(resultHtml)
Esempio n. 4
0
def login_result(request):  # 登陆的结果
    password = request.POST['password']
    if password == '':
        return HttpResponse('登陆失败!请填写密码')
    email = request.POST['email']
    if email == '':
        return HttpResponse('登陆失败!请填写邮箱')
    u = User()
    u.email = email
    u.password = password
    try:
        user = User.objects.get(email=email)  # user是指从数据库里面查找的邮箱为email的用户
    except User.DoesNotExist:
        return HttpResponse("账户不存在")
    if user.password == hashlib.sha1(u.password).hexdigest():  # u是登陆之时填写的用户
        if user.effective == 1:
            result = get_template('login_result.html')  # 比较数据库的用户的密码和填写的密码是否一致
            resultHtml = result.render(Context())
            request.session['user'] = user
            return HttpResponseRedirect("/index/")
        else:
            return HttpResponse("您的帐号已被删除或封停,具体情况请联络技术部负责人予以解决!")
    else:
        return HttpResponse("密码错误")
Esempio n. 5
0
def reg_result(request): # 注册的结果页面
    u=User() # 新建一个User对象,把它存入数据库
    password =  request.POST['password'] #从表单里拿到密码
    if password=='': # 没填密码
        return HttpResponse('注册失败!请填写密码')
    email =  request.POST['email']
    if email=='':# 没填邮箱
        return HttpResponse('注册失败!请填写邮箱')
    name =  request.POST['name']
    if name=='':
        return HttpResponse('注册失败!请填写真实姓名')
    invitecode =  request.POST['invitecode']
    if invitecode=='':
        return HttpResponse('注册失败!请填写邀请码')
    sec = request.POST['sec']
    if sec==u'主席团':
        u.sec=Section.objects.get(id=2)
    if sec==u'技术部':
        u.sec=Section.objects.get(id=1)
    if sec==u'运营部':
        u.sec=Section.objects.get(id=3)
    if sec==u'宣传部':
        u.sec=Section.objects.get(id=4)
    if sec==u'财务部':
        u.sec=Section.objects.get(id=5)
    
    college = request.POST['college']
    major = request.POST['major']
    entry_year = request.POST['entry_year']
    grade = request.POST['grade']
    campus = request.POST['campus']
    sex = request.POST['sex']
    phone = request.POST['phone']
    province = request.POST['province']
    city = request.POST['city']
    area = request.POST['area']
    qq = request.POST['qq']
    love = request.POST['love']
    #city = request.POST['city']

    u.school='南开大学'
    u.email=email
    u.password=hashlib.sha1(password).hexdigest() # 这是生成hash值代替明文的密码
    u.name=name
    u.college=college
    u.major=major
    u.entry_year=entry_year
    u.grade=grade
    u.campus=campus
    u.sex=sex
    u.phone=phone
    u.province=province
    u.city=city
    u.area=area
    u.qq=qq
    u.love=love
    u.effective=1
    u.authority=0

    try: # 测试邮箱是否已经被使用过了
        User.objects.get(email = email)
    except User.DoesNotExist:
        pass
    else:
        return HttpResponse("该邮箱已被注册,请您换一个未被注册过的有效邮箱进行注册!")

    try:
        c=Code.objects.get(code=invitecode)
        if c.effective==0:
            return HttpResponse("该邀请码已经被使用过了!请确认您拥有正确的邀请码!")
        else:
            u.save()
            c.effective=0
            c.use =User.objects.get(email = email)  # 把验证码和用户关联上
            c.save()
    except Code.DoesNotExist:
        return HttpResponse("该邀请码不存在!请确认您拥有正确的邀请码!")
    
    request.session['user']=u # 把user对象放到session里面去
    result=get_template('result.html')
    resultHtml=result.render(Context())
    return HttpResponse(resultHtml)
Esempio n. 6
0
def reg_result(request):  # 注册的结果页面
    u = User()  # 新建一个User对象,把它存入数据库
    password = request.POST['password']  #从表单里拿到密码
    if password == '':  # 没填密码
        return HttpResponse('注册失败!请填写密码')
    email = request.POST['email']
    if email == '':  # 没填邮箱
        return HttpResponse('注册失败!请填写邮箱')
    name = request.POST['name']
    if name == '':
        return HttpResponse('注册失败!请填写真实姓名')
    invitecode = request.POST['invitecode']
    if invitecode == '':
        return HttpResponse('注册失败!请填写邀请码')
    sec = request.POST['sec']
    if sec == u'主席团':
        u.sec = Section.objects.get(id=2)
    if sec == u'技术部':
        u.sec = Section.objects.get(id=1)
    if sec == u'运营部':
        u.sec = Section.objects.get(id=3)
    if sec == u'宣传部':
        u.sec = Section.objects.get(id=4)
    if sec == u'顾问团':
        u.sec = Section.objects.get(id=5)

    college = request.POST['college']
    major = request.POST['major']
    entry_year = request.POST['entry_year']
    grade = request.POST['grade']
    campus = request.POST['campus']
    sex = request.POST['sex']
    phone = request.POST['phone']
    province = request.POST['province']
    city = request.POST['city']
    area = request.POST['area']
    qq = request.POST['qq']
    love = request.POST['love']
    #city = request.POST['city']

    u.school = '南开大学'
    u.email = email
    u.password = hashlib.sha1(password).hexdigest()  # 这是生成hash值代替明文的密码
    u.name = name
    u.college = college
    u.major = major
    u.entry_year = entry_year
    u.grade = grade
    u.campus = campus
    u.sex = sex
    u.phone = phone
    u.province = province
    u.city = city
    u.area = area
    u.qq = qq
    u.love = love
    u.effective = 1
    u.authority = 0

    try:  # 测试邮箱是否已经被使用过了
        User.objects.get(email=email)
    except User.DoesNotExist:
        pass
    else:
        return HttpResponse("该邮箱已被注册,请您换一个未被注册过的有效邮箱进行注册!")

    try:
        c = Code.objects.get(code=invitecode)
        if c.effective == 0:
            return HttpResponse("该邀请码已经被使用过了!请确认您拥有正确的邀请码!")
        else:
            u.save()
            c.effective = 0
            c.use = User.objects.get(email=email)  # 把验证码和用户关联上
            c.save()
    except Code.DoesNotExist:
        return HttpResponse("该邀请码不存在!请确认您拥有正确的邀请码!")

    request.session['user'] = u  # 把user对象放到session里面去
    result = get_template('result.html')
    resultHtml = result.render(
        Context(
            {
                'result':
                'You have registered successfully! <a href="/index/">click this to turnback</a>',
                'meta': 'http-equiv="refresh" content="2;url=/index/" '
            },
            autoescape=False))  #防止将'<'、 '/'和'>'自动转义
    return HttpResponse(resultHtml)