Пример #1
0
def create_empty_user(uuid, service_provider, access_token, **additional):
    try:
        user = Users.objects.get(uuid = uuid)
        user.delete()
    except:
        pass

    user = Users(uuid = uuid, login_service = service_provider, access_token = access_token)

    if 'refresh_token' in additional:
        user.refresh_token = additional['refresh_token']

    user.save()

    return uuid
Пример #2
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"}')
Пример #3
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)
Пример #5
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)    
Пример #6
0
def useradded(request):
    uname = request.POST.get('username')
    pword = request.POST.get('password')
    pword2 = request.POST.get('password2')
    if uname == '' or pword == '' or pword2 == '':
	return HttpResponse('please fill in all fields')
    else:
	try:
	    currentuser = Users.objects.get(username=uname)
	except:
    	    if pword == pword2:
		addnewuser = Users(username=uname, password=pword)
		addnewuser.save()
		return render(request, 'login/useradded.html',
	    	    {"username": uname,
	    	    "password": pword,
	    	    "worked": "yes",
	    	    })
    	    else:
		return HttpResponse("your passwords don't match")
	return HttpResponse("that username already exists")
Пример #7
0
    def add(self,uname, pword):
	err_code = SUCCESS
	count = 0
	existed_users = Users.objects
	#print "hello"
	#print existed_users 
	#print invalidusername(uname)
	if invalidusername(uname) or uname =="" or len(uname)==0:
	    err_code = ERR_BAD_USERNAME
	    return (err_code, count)
	if invalidpassword(pword)or pword =="" or len(pword)==0:
	    err_code = ERR_BAD_PASSWORD
	    return (err_code, count)
	#print existed_users.filter(username = uname)
        #print existed_users.filter(username = uname)==[]
	if len(existed_users.filter(username = uname))==0: # user doesn't exist before  
	   user = Users(username = uname, password = pword)
	   user.save()
	   count = user.count
	else:
	   err_code = ERR_USER_EXISTS
	return (err_code, count)
Пример #8
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
Пример #9
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})
Пример #10
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("初始化完成!")
Пример #11
0
def init(request):
    username = "******"
    password = "******"
    users = Users()
    users.username = username
    users.password = password
    try:
        users.save()
    except IntegrityError:
        return HttpResponse("用户名重复!")
    return HttpResponse("ok")
Пример #12
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"}')
Пример #13
0
    def test_success_login(self):
	earlieruser = Users(username= "******", password = "******")
	earlieruser.save()
	newuser = UsersModel()
	self.assertEqual(newuser.login("user", "password"), (SUCCESS,2))
Пример #14
0
    def test_username_password_mismatch_login(self):
	earlieruser = Users(username= "******", password = "******")
	earlieruser.save()
	newuser = UsersModel()
	self.assertEqual(newuser.login("user", "wordpass"), (ERR_BAD_CREDENTIALS,0))
Пример #15
0
    def test_repetivtive_add_user(self):
	earlieruser = Users(username= "******", password = "******")
	earlieruser.save()
	newuser = UsersModel()
	self.assertEqual(newuser.add("user", "password"), (ERR_USER_EXISTS,0))