Exemplo n.º 1
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()

            registered = True
        else:
            print(user_form.errors,profile_form.errors)

    else:
        user_form = UserForm
        profile_form = UserProfileInfoForm

    return render(request, 'myapp/register.html', {'user_form':user_form,
    'profile_form':profile_form,'registered':registered})
Exemplo n.º 2
0
def login(request):
    if request.method == 'GET':
        return render(request, 'login.html')

    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            # 登录的设置
            # 1.通过用户名和密码获取当前的user对象  ====>> auth.authenticate()
            user = Users.objects.filter(username=form.cleaned_data['username']).first()
            if user:
                # 将user.password和form.cleaned_data['password']进行校验
                if check_password(form.cleaned_data['password'], user.password):
                    # 校验成功
                    # 1.向cookie中设置随机参数ticket
                    res = HttpResponseRedirect(reverse('myapp:index'))
                    # set_cookie(key, value, max_age='', expires='')
                    ticket = get_ticket()
                    res.set_cookie('ticket', ticket, max_age=10)
                    # 2.向user_ticket中存这个ticket和user的对应关系
                    UserTicket.objects.create(user=user, ticket=ticket)

                    return res

                else:
                    return render(request, 'login.html')
            else:
                # 用户名不存在
                return render(request, 'login.html')
            # 2.设置cookie中的随机值  =====>> auth.login()
            # 3.设置user_ticket中的随机值
        else:
            return render(request, 'login.html')
Exemplo n.º 3
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response(
            'register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
Exemplo n.º 4
0
def update_my_account(request):
    # user_profile = UserProfile.objects.get(user__pk=request.user.id)
    # frm_user_profile = UserProfileForm(request.POST, instance=user_profile)
    if request.method == 'POST':
        frm_user = UserForm(request.POST, instance=request.user)
        if frm_user.is_valid():
            frm_user.save()
            messages.success(request, 'Profile details updated successfully.')
        else:
            messages.error(request, f'error: {frm_user.errors.as_data()}')
    return redirect('/accounts/myaccount')
Exemplo n.º 5
0
def register(request):
    registered = False
    verifCodeAlert = False
    try:
        code = models.verifyCodes.objects.all().filter(inUse=False)[0]
    except:
        return HttpResponse("Ilość kont wyczerpana")
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        margonemAccountCheck = codegen.checkCode(code.code, request.POST.get("mprofile"))
        if user_form.is_valid() and profile_form.is_valid() and margonemAccountCheck == True:
            user = user_form.save()
            user.set_password(user.password)
            profile = profile_form.save(commit=False)
            profile.verifCode = code
            code.inUse = True
            code.save()
            registered = True
            user.save()
            profile.user = user
            profile.save()
            user = authenticate(username = user.username, password = user.password)
            return HttpResponseRedirect(reverse('user_login'))

        else:

            registerAlert = dict()
            try:
                if profile_form.errors['mprofile']:
                    registerAlert.update({'Podano błędny, lub zajęty link do profilu margonem': "Validmprofile"})
            except:
                if margonemAccountCheck == False:
                    registerAlert.update({'Nie znaleziono kodu weryfikacyjnego na profilu margonem': "validCode"})
            try:
                if user_form.errors['username']:
                    registerAlert.update({'Login najprawdopodobniej jest zajęty': "validLogin"})
            except:
                pass
            try:
                if user_form.errors['password']:
                    registerAlert.update({'Hasło jest zbyt słabe': "validpassword"})
            except:
                pass
            print(user_form.errors.keys())
            user_form = UserForm()
            profile_form = UserProfileInfoForm()
            return render(request, 'registration.html', context={'user_form': user_form,
                                                                 'profile_form': profile_form,
                                                                 'registered': registered,
                                                                 'verCode': code.code,
                                                                 'alerts': registerAlert})
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(request, 'registration.html',context={'user_form':user_form,
                                                        'profile_form':profile_form,
                                                        'registered':registered,
                                                        'verCode':code.code,
                                                        'verifCodeAlert':verifCodeAlert})
Exemplo n.º 6
0
def register(request):
    if request.method == 'GET':
        return render(request, 'register.html')

    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            password = make_password(form.cleaned_data['password'])
            Users.objects.create(username=form.cleaned_data['username'], password=password)

            return HttpResponseRedirect(reverse('myapp:login'))

        else:
            return render(request, 'register.html')
Exemplo n.º 7
0
def loging(request):
	if request.method == 'GET':
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		if user_form.is_valid() and profile_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
			profile = profile_form.save(commit=False)
			profile.user = user
			profile.save()
			return HttpResponseRedirect('/') 
		else:
			a=UserForm()
			b=UserProfileForm()
	return render(request, 'register.html', locals())
Exemplo n.º 8
0
def regist(request):  # 注册
    if request.method == 'GET':
        return render(request, 'reg-log/sign-up.html')
    elif request.method == 'POST':
        form = UserForm(request.POST)
        # 验证数据的完整性
        if form.is_valid():
            code = get_code(form.cleaned_data.get('telephone')).decode()
            if code == form.cleaned_data.get('code'):
                form.save()  # 无错时保存数据
                return redirect(reverse('myapp:login'))
            else:
                return render(request, 'reg-log/sign-up.html',
                              {'errors': '验证失败'})
        errors = form.errors  # 默认情况下,是html的错误信息
        return render(request, 'reg-log/sign-up.html', locals())
Exemplo n.º 9
0
 def post(self, request, name):
     myform = UserForm(request.POST)
     userid = request.POST['userid']
     if myform.is_valid():
         if Guser.objects.filter(userid=userid):
             messages.warning(request, 'User is already exists :(')
         else:
             ob = Auser.objects.get(userid=name)
             aid = ob.id
             userid = request.POST['userid']
             password = request.POST['password']
             Guser.objects.create(userid=userid,
                                  password=password,
                                  guser_id=aid)
             messages.success(request, 'User Created Succesfully :)')
     else:
         messages.success(request, 'User is not created :)')
     return HttpResponseRedirect(request.path)
Exemplo n.º 10
0
 def get(self, request, name):
     myform = UserForm()
     ob = Auser.objects.get(userid=name)
     aid = ob.id
     data = Guser.objects.filter(guser_id=aid)
     return render(request, 'panel.html', {
         'myform': myform,
         'adminuser': name,
         'data': data
     })
Exemplo n.º 11
0
def my_account(request):
    user = User.objects.get(pk=request.user.id)
    user_profile = UserProfile.objects.get(user__pk=request.user.id)
    stock_transactions = Transaction.objects.filter(user=request.user)
    frm_user_profile = UserProfileForm(instance=user_profile)
    frm_user = UserForm(instance=user)
    context = {
        'frm_user': frm_user,
        'frm_user_profile': frm_user_profile,
        'stock_transactions': stock_transactions
    }
    return render(request, 'my_account.html', context=context)
Exemplo n.º 12
0
def userform(request):
    form = UserForm()
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            form.save()
            # return index(request)
        else:
            print("error")
    return render(request, 'myapp/forms.html', {'form': form})
def register(request):
    userform = UserForm()
    userprofileform = UserProfileForm()
    registered = False
    if request.method == 'POST':
        userform = UserForm(data=request.POST)
        userprofileform = UserProfileForm(data=request.POST)
        if userform.is_valid() and userprofileform.is_valid():
            user = userform.save()
            user.set_password(user.password)
            user.save()

            userprofile = userprofileform.save(commit=False)
            userprofile.user = user
            if 'profile_pic' in request.FILES:
                userprofile.profile_pic = request.FILES['profile_pic']
            userprofile.save()
            registered = True
        else:
            print(userform.errors, userprofileform.errors)

    return render(
        request, 'myapp/register.html', {
            'registered': registered,
            'userform': userform,
            'userprofileform': userprofileform
        })
Exemplo n.º 14
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        # print(user_form)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            # our_user = UserProfileInfo(user = user_form.save(),indicesList = "'NDVI':'(nir-r)/(nir+r)'")
            # print(our_user)
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            # our_user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            # userInfo = UserProfileInfo.objects.all()
            # print(userInfo)
            if 'profile_pic' in request.FILES:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 15
0
def register(request):
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)

        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user

            profile.save()

            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:

        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'registration/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
        })
Exemplo n.º 16
0
def register(request):

    registered = False

    if request.method == 'POST':

        # Get info from "both" forms
        # It appears as one form to the user on the .html page
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        # Check to see both forms are valid
        if user_form.is_valid() and profile_form.is_valid():

            # Save User Form to Database
            user = user_form.save()
            # Hash the password
            user.set_password(user.password)
            # Update with Hashed password
            user.save()

            # Now we deal with the extra info!

            # Can't commit yet because we still need to manipulate
            profile = profile_form.save(commit=False)
            # Set One to One relationship between
            # UserForm and UserProfileInfoForm
            profile.user = user

            # Check if they provided a profile picture
            if 'profile_pic' in request.FILES:
                print('found it')
                # If yes, then grab it from the POST form reply
                profile.profile_pic = request.FILES['profile_pic']

            # Now save model
            profile.save()

            # Registration Successful! registered is used in the context of registration.html
            registered = True

        else:
            # One of the forms was invalid if this else gets called.
            print(user_form.errors, profile_form.errors)

    else:
        # Was not an HTTP post so we just render the forms as blank.
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    # This is the render and context dictionary to feed
    # back to the registration.html file page.
    return render(
        request, 'myapp/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 17
0
def register(request):
    if request.method == 'POST':
        userForm = UserForm(request.POST)  #接收表单的POST提交数据
        if userForm.is_valid():
            name = userForm.cleaned_data['name']
            password = userForm.cleaned_data['password']
            repassword = userForm.cleaned_data['repassword']
            email = userForm.cleaned_data['email']
            QQ = userForm.cleaned_data['QQ']
            if password != repassword:
                return HttpResponseRedirect("/myapp/reg/")
            else:
                User.objects.create(username=name,
                                    password=password,
                                    email=email,
                                    QQ=QQ)  #注册,插入数据库
                return render(request, 'success.html')

        else:
            return HttpResponseRedirect("/myapp/reg/")
    else:
        userForm = UserForm()
        return render(request, 'register.html', {'regform': userForm})
Exemplo n.º 18
0
def auth_view(request):
    user_form = UserForm(data=request.POST)
    user = authenticate(username=user_form.username,
                        password=user_form.password)
    if user is not None and user.is_active:
        login(request, user)
        # Redirect to a success page.
        return HttpResponseRedirect('/myapp/')
    else:
        # Return an 'invalid login' error message
        #return invalid(self)
        print user_form.errors
    return render_to_response('myapp/base_login.html',
                              {'user_form': user_form}, context)
Exemplo n.º 19
0
def userforms(request):
    form = UserForm()

    if request.method == "POST":
        form = UserForm(request.POST)

        if form.is_valid():
            print("The Form Is Valid! ")
            form.save(commit=True)
            return index(request)
        else:
            print("The Form Is Not Valid! ")
    return render(request, 'userform.html', {'form':form})
Exemplo n.º 20
0
def user(request):
    if request.method == 'GET':
        # フォームを規定値で初期化
        form = UserForm(initial={
            'name': '匿名',
            'age': 20,
            'weight': 50.3,
            'height': 175.2,
            'registed': timezone.now(),
            'single': True,
        })

        context = { 'form': form }  # コンテキストにフォームを納格
        return render(request, 'myapp/user.html', context)  # 描画
    else:
        return HttpResponse('未実装')
def register(request):
    registered= False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            registered = True
        else:
            print(user_form.errors)
    else:
        user_form = UserForm()
    return render(request,'myapp/registration.html',{'user_form':user_form,'registered':registered})
Exemplo n.º 22
0
def register(request):

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        if user_form.is_valid():

            user = user_form.save()
            user.set_password(user.password)
            user.save()
            alert = 'Account Created Successfully ! Please Login'
            return render(request, 'myapp/login.html', {'alert': alert})

        else:
            print(user_form.errors)
    else:
        user_form = UserForm()

    return render(request, 'myapp/register.html', {'user_form': user_form})
Exemplo n.º 23
0
def signup_profile(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            user = form.save()
            # user.is_active = False
            user.save()

            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('myapp:home')
    else:
        form = UserForm()

    return render(request, 'registration/user_signup.html', {
        'form': form,
    })
Exemplo n.º 24
0
def signup(request):
	registered = False
	if request.method == 'POST':
		user_form = UserForm(data=request.POST)		
		if user_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
			
			registered = True

			return render(request, 'index.html', {})

		else:
			print(user_form.errors)
	else:
		user_form = UserForm()
		# profile_form = UserProfileInfoForm()

	return render(request, 'signup.html', {'user_form':user_form, 'registered':registered})
Exemplo n.º 25
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = UserProfileInfoForm(request.POST)

        # check for validity of both the forms
        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save()
            # set_password will take in the raw_password and applies hashing
            user.set_password(user.password)
            # save the above change
            user.save()

            # contains website link and profile_pic
            profile = profile_form.save(
                commit=False)  # creates object but don't persist into db
            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True

        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'myapp/registration.html', {
            'registered': registered,
            'user_form': user_form,
            'profile_form': profile_form
        })
Exemplo n.º 26
0
def register(request):

    registered = False
    if request.method == "POST":
        # this garp data from user form when user register
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            """ grap user from user_form then save it
                    then hash th password then save it
            """
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            # the additional fields
            """ this won't save directr;y to the database
                and this use the OneToOneField we created
            """
            profile = profile_form.save(commit=False)
            profile.user = user
            """ request.FILES for pdf/img/cv """
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()
            registered = True

        else:
            print(user_form.errors, profile_form.errors)

    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'myapp/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 27
0
def signin(request):
    context = RequestContext(request)
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            registered = True
            newsfeed = Newsfeed(newsfeed_id=user.username, user=user)
            newsfeed.save()
        else:
            print user_form.errors
    else:
        user_form = UserForm()

    return render_to_response('myapp/base_signin.html', {
        'user_form': user_form,
        'registered': registered
    }, context)
Exemplo n.º 28
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response(
        'register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        }, context)