Пример #1
0
 def create(self, validated_data):
     user = Users()
     password = validated_data.get('password')
     password = make_password(password)  # 对密码加密
     user.uid = validated_data.get('uid')
     user.password = password
     user.save()
     return user
Пример #2
0
def init(request):
    users = Users()
    users.username = "******"

    # md5 = hashlib.md5()
    # md5.update('初始化完成!'.encode())
    # pw = md5.hexdigest()
    pw = my_md5("222")
    users.password = pw
    users.save()
    return HttpResponse("初始化完成!")
Пример #3
0
def init(request):
    username = "******"
    password = "******"
    users = Users()
    users.username = username
    users.password = password
    try:
        users.save()
    except IntegrityError:
        return HttpResponse("用户名重复!")
    return HttpResponse("ok")
Пример #4
0
    def post(self, request):

        reg_form = RegisterForm(request.POST)
        if reg_form.is_valid():
            cleaned_data = reg_form.cleaned_data
            user = Users()
            user.phone = cleaned_data.get('phone')
            user.nickname = cleaned_data.get('nickname')
            user.password = set_password(cleaned_data.get('password2'))
            user.save()
            login(request, user)
            return redirect('login:info')
        else:
            return render(request, 'login/register.html', {'form': reg_form})
Пример #5
0
def newRegistration(request):
    from bcrypt import hashpw, gensalt

    data = json.loads(request.body)
    username = data['accountname']
    accountpassword = data['accountpassword']
    accountemail = data['accountemail']
    plaintext_password = accountpassword
    hashed = hashpw(plaintext_password, gensalt())

    if Users.objects.filter(username=username) > 0:
        return HttpResponse('{"status":"This account name is unavailable"}')
    else:
        newUser = Users(username=username, password=hashed, email=accountemail)
        newUser.save()
        return HttpResponse('{"status":"OK"}')
Пример #6
0
def signup(request):

    if request.method == 'POST':
        print request.POST.get('email')

        userdata = Users(email=request.POST.get('email'),
                         password=bcrypt.encrypt(request.POST.get('password')))
        userdata.save()

        response_text = textwrap.dedent('''\
            <html>
            <head>
                <title>Greetings to the world</title>
            </head>
            <body>
               Hello ''' + request.POST.get('email') +
                                        ''' <a href="/users">Login</a>	
            </body>
            </html>
        ''')
    else:

        response_text = textwrap.dedent('''\
            <html>
            <head>
                <title>Greetings to the world</title>
            </head>
            <body>
                <h1>Signup</h1>
                <p>Hello, world!</p>
				<form method="POST" src="">
				Email
				<input type="text" name="email" value="" />
				Password
				<input type="text" name="password" value="" />
				<input type="submit" name="signup" value="Signup" />
				</form>
				<a href="/users">Login</a>				
            </body>
            </html>
        ''')
    return HttpResponse(response_text)
def AddStudent(request):
    if request.method=="POST":
        
        print(json.loads(request.body))
        data=json.loads(request.body)
        user_name=data['first_name']+"."+data['roll_no']
        password=data['first_name']
        first_name=data['first_name']
        last_name=data['last_name']
        roll_no=data['roll_no']
        father_name=data['father_name']
        email=data['email']
        section=data['section']
        branch=data['branch']
        phone_no=data['phone_no']
        savedata=StudentDetail(user_name=user_name,password=password,first_name=first_name,last_name=last_name,roll_no=roll_no,father_name=father_name,email=email,section=section,branch=branch,phone_no=phone_no)
        savedata.save()
        user=Users(username=user_name,password=password,id_type="student")
        user.save()
        return JsonResponse("success",safe=False)
Пример #8
0
def mmoLogin(request):
    from bcrypt import hashpw, gensalt
    import random
    import string
    import hashlib

    def random_md5(string_length=25, slug=False, number=1):
        hashes = []
        for n in range(number):
            r = ''.join(
                random.choice(string.letters + string.digits)
                for i in xrange(string_length))
            m = hashlib.md5()
            m.update(r)
            if slug == True:
                hashes.append(m.hexdigest()[:7])
            else:
                hashes.append(m.hexdigest())
        return hashes

    data = json.loads(request.body)
    login = data['login']
    password = data['password']

    #Get User profile
    if Users.objects.filter(username=login) > 0:
        user = Users.objects.get(username=login)
        attemptPass = str(user.password).encode('utf-8')
        enteredPass = str(password).encode('utf-8')
        if hashpw(enteredPass, attemptPass) == attemptPass:
            #Need To delete active Login Session
            ActiveLogins.objects.filter(user_id_id=user.pk).delete()
            #Create New Session
            newKey = str(random_md5(7, True, 1)).replace("['",
                                                         "").replace("']", "")

            newSession = ActiveLogins(
                user_id_id=user.pk,
                session_key=newKey,
            )
            newSession.save()
            return HttpResponse('{"status":"OK","sessionkey":"' + str(newKey) +
                                '","userid":' + str(user.pk) + '}')
        else:
            HttpResponse(
                '{"status":"Login Information is not correct. Check your username and password."}'
            )

    else:
        return HttpResponse(
            '{"status":"Login Information is not correct. Check your username and password."}'
        )

    plaintext_password = accountpassword
    hashed = hashpw(plaintext_password, gensalt())

    if Users.objects.filter(username=username) > 0:
        return HttpResponse('{"status":"This account name is unavailable"}')
    else:
        newUser = Users(username=username, password=hashed, email=accountemail)
        newUser.save()
        return HttpResponse('{"status":"OK"}')