Exemplo n.º 1
0
def do_register(request):
    try:
        if request.method == 'POST':
            userform = UserForm(request.POST, request.FILES)
            if userform.is_valid():
                user = User.objects.create(
                    username=userform.cleaned_data['username'],
                    password=make_password(userform.cleaned_data['password']),
                    email=userform.cleaned_data['email'],
                    url=userform.cleaned_data['url'],
                    avatar=request.FILES.get('avatar'),
                )
                user.save()

                # 进行登录操作和验证
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                login(request, user)
                print('source_url', request.POST.get('source'))
                return redirect(request.POST.get('source'))
            else:
                return render(request, 'failure.html',
                              {'reason': userform.errors})
        else:
            userform = UserForm()

    except Exception as e:
        logger.error(e)
    return render(request, 'reg.html', locals())
Exemplo n.º 2
0
def signup(request):
    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            Name = request.POST.get('Name', '')
            Email_ID = request.POST.get('Email_ID', '')
            DOB = request.POST.get('DOB', '')
            Flag = request.POST.get('Flag', '')
            ORG = request.POST.get('ORG', '')
        user_obj = Post(Name=Name,
                        Email_ID=Email_ID,
                        DOB=DOB,
                        Flag=Flag,
                        ORG=ORG)
        user_obj.save()

        return render(request, 'blog/signup.html', {
            'user_obj': user_obj,
            'is_registered': True
        })
    else:
        form = UserForm()

        return render(request, 'blog/signup.html', {'form': form})
Exemplo n.º 3
0
def register(request):
    if request.method == 'POST':
        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()
            prof = profile_form.save(commit=False)
            prof.user = user
            if 'picture' in request.FILES:
                prof.picture = request.FILES['picture']
                print prof.picture
                print type(prof.picture)
            prof.save()
            username = request.POST.get('username')
            password = request.POST.get('password')
            user = authenticate(username=username, password=password)
            login(request, user)
            request.session['notice'] = u'注册成功*%s*' % username
            return redirect('/blog/')
        else:
            print user_form.errors
            error = user_form.errors.as_data().values()[0][0].messages[0]
            print type(error)
            return render(request, 'blog/auth/register.html',
                          {'error': error})
    else:
        return render(request, 'blog/auth/register.html')
Exemplo n.º 4
0
def register(request):
	context = RequestContext(request)

	registered = False

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

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

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

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

			profile.save()
			registered=True

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

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

	return render_to_response(
		'blog/register.html',
		{'user_form':user_form, 'profile_form':profile_form, 'registered':registered},
	context)					
Exemplo n.º 5
0
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

        # Invalid forms
        else:
            print user_form.errors

    # Not a Post request
    else:
        user_form = UserForm()

    # Render the template depending on the context.
    return render(request,
            'blog/register.html',
            {'user_form': user_form, 'registered': registered} )
Exemplo n.º 6
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.º 7
0
def signUp(request):
    error = False
    if request.method == 'POST':
        form = UserForm(request.POST)
        profile_form = ProfileForm(request.POST, request.FILES)
        if all((form.is_valid(), profile_form.is_valid())):
            data_user = {
                'username': form.cleaned_data['username'],
                'password': form.cleaned_data['password'],
                'email': form.cleaned_data['email'],
                'first_name': form.cleaned_data['first_name'],
                'last_name': form.cleaned_data['last_name']
            }
            try:
                user = requests.post(BASE_URL + '/api/users/create/',
                                     data=data_user)
                if user.status_code != 201:
                    raise Exception('User already exist')
                user = user.json()
                data_profile = {'user': user['id']}

                if 'picture' in profile_form.cleaned_data:
                    file_profile = {
                        'picture': profile_form.cleaned_data['picture']
                    }
                else:
                    file_profile = {}

                data_put = {
                    'first_name': form.cleaned_data['first_name'],
                    'last_name': form.cleaned_data['last_name']
                }

                r = login_api(user['username'], form.cleaned_data['password'])

                request.session['token'] = r.json()['auth_token']
                request.session['me'] = requests.get(
                    BASE_URL + '/api/users/me/',
                    headers=get_header(request)).json()

                profile = requests.post(BASE_URL + '/api/profile/',
                                        data=data_profile,
                                        files=file_profile,
                                        headers=get_header(request)).json()
                user = requests.put(BASE_URL + '/api/user/' + str(user['id']) +
                                    '/',
                                    data=data_put,
                                    headers=get_header(request)).json()
                return redirect('home')
            except Exception as e:
                error = True

    form = UserForm()
    profile_form = ProfileForm()
    # if request.user.is_authenticated():
    #     redirect('home')
    return render(request, 'blog/signUp.html', locals())
Exemplo n.º 8
0
def signup(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            new_user = User.objects.create_user(**form.cleaned_data)
            login(request, new_user)
            return redirect('/')
    else:
        form = UserForm()
    return render(request, 'registration/signup.html', {'form': form})
Exemplo n.º 9
0
def register(request):
    if request.method == 'POST':
        forms = UserForm(request.POST)
        if forms.is_valid():
            print forms.cleaned_data
            return HttpResponse('ok')
    else:
        forms = UserForm()

    return render(request, 'register.html', {'forms': forms})
Exemplo n.º 10
0
def register(request):
	if request.method == 'POST':
		uf = UserForm(request.POST)
		if uf.is_valid():
			uf.instance.set_password(uf.instance.password)
			uf.instance.is_staff = True
			uf.save()
			return HttpResponse('ok')
	else:
		uf = UserForm()
	return render(request,'register.html',{'uf':uf})
Exemplo n.º 11
0
def register(request):
	if request.method == 'POST':

		uf = UserForm(request.POST)
		if uf.is_valid():
		    uf.instance.password = hashlib.sha1(uf.instance.password+uf.instance.username).hexdigest()
		    uf.save()
		    return HttpResponseRedirect('/login/')
	else:
		uf = UserForm()
	return render(request,'register.html',{'uf':uf})
Exemplo n.º 12
0
def create_user(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.user_permissions.add('blog.add_post', 'blog.change_post', 'blog.delete_post')
            user.save()
            return redirect('index')
    else:
        form = UserForm()
    return render(request, 'registration/signin.html', {'form': form})
Exemplo n.º 13
0
def register(request):
	context = RequestContext(request)
	if request.method == 'POST':
		form = UserForm(request.POST, request.FILES)
		if form.is_valid(): # is the form valid
			form.save(commit=True) # yes and save to db
			return redirect(index)
		else:
			print form.errors  # no, display error to end user
	else:
		form = UserForm()
	return render_to_response('blog/register.html', {'form': form}, context)
Exemplo n.º 14
0
def register(request):
	if request.method == 'POST':
		uf = UserForm(request.POST,request.FILES)
		if uf.is_valid():
			user = User.objects.create_user(username=uf.cleaned_data['username'],email="*****@*****.**")
			user.set_password(uf.cleaned_data['password'])
			user.save()
			Employee.objects.create(user=user,tel=uf.cleaned_data['tel'],address=uf.cleaned_data['address'],headImg=uf.cleaned_data['headImg'])
			return HttpResponseRedirect('/login/')
	else:
		uf = UserForm()
	return render(request,'register.html',{'uf':uf})
Exemplo n.º 15
0
def register(request):
	if request.method == 'POST':
		uf = UserForm(request.POST)
		if uf.is_valid():
			username = uf.cleaned_data['username']
			password = uf.cleaned_data['password']
			user = User.objects.create_user(username = username)
			user.set_password(password)
			user.save()
			return HttpResponseRedirect('/index/')
	else:
		uf = UserForm()
	return render(request, 'register.html', {'uf': uf})
Exemplo n.º 16
0
def register(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user = models.User()
            print(form.cleaned_data)
            user.user_id = form.cleaned_data['user_id']
            user.password = form.cleaned_data['password']

            user.save()
        return login(request)
    else:
        form = UserForm().as_ul()
    return render(request, 'blog/register.html', {'form': form})
Exemplo n.º 17
0
def register(request):
	if request.method == 'POST':
		uf = UserForm(request.POST)
		if uf.is_valid():
			username = uf.cleaned_data['username']
			password = uf.cleaned_data['password']
			user = User.objects.create_user(username=username)
			user.set_password(password)
			user.user_permissions.add('open_comment','reply_comment','close_comment')
			user.save()
			return HttpResponseRedirect('/login/')
	else:
		uf = UserForm()
	return render(request,'login.html',{'uf':uf})
Exemplo n.º 18
0
Arquivo: views.py Projeto: hwddzx/blog
 def post(self, request):
     # 接收参数
     data = request.POST
     # 验证数据合法性
     form = UserForm(data)
     if form.is_valid():
         # 保存数据库
         user = User()
         user.phone = form.cleaned_data.get('phone')
         user.password = set_password(form.cleaned_data.get('password'))
         user.save()
         # 跳转到登录
         return redirect('blog:登录')
     else:
         return render(request, 'blog/reg.html', context=form.errors)
Exemplo n.º 19
0
def login_user(request):
	if request.method == 'POST':
		uf = UserForm(request.POST)
		if uf.is_valid():
			username = uf.cleaned_data['username']
			password = uf.cleaned_data['password']
			user = authenticate(username=username,password=password)
			if user is not None:
				login(request,user)
				return HttpResponseRedirect('/index/')
			else:
				return HttpResponseRedirect('/index/')
	else:
		uf = UserForm()
	return render(request,'login.html',{'uf':uf})
Exemplo n.º 20
0
def register(request):
    # boolean value
    # Установлено в False при инициализации.
    # Изменим на True при успешной регистрации.

    registered = False

    # Если HTTP POST, обработаем форму.
    if request.method == 'POST':
        # Получаем информацию из форм.
        # Мы используем две формы UserForm и UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)
        # Если обе формы прошли проверку...
        if user_form.is_valid() and profile_form.is_valid():
            # Сохраним данные пользователя из формы в database.
            user = user_form.save()

            # Хешируем пароль с помощью set_password method.

            user.set_password(user.password)
            user.save()
            # Пока пользователь настраивает свой профиль не выполнять commit=False.

            profile = profile_form.save(commit=False)
            profile.user = user
            # Юзер хочет картинку?
            # Если да, предоставим ему поле для ввода картинки.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Сохранить экземпляр модели UserProfile.
            profile.save()

            # Изменить переменную при успешной регистрации.
            registered = True
        else:
            print user_form.errors, profile_form.errors
            # Не HTTP POST, строим два экземпляра ModelForm .
    # Эти формы пустые , предназначены для пользовательских вводов.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()


    # Render the template depending on the context.
    return render(request, 'blog/register.html',
                  {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
Exemplo n.º 21
0
def register(request):

	if request.method == "POST":
		uf = UserForm(request.POST)
		if uf.is_valid():
			username = uf.instance.username
			password= uf.instance.password
			uf.instance.password = hashlib.sha1(username+password).hexdigest()
			uf.save()

			response = HttpResponseRedirect('/login/')
			# response.set_cookie(key='username',value=username)
			return response
	else:
		uf = UserForm()
	return render(request,'register.html',{'uf':uf})
Exemplo n.º 22
0
def home(request):
    user_form = UserForm()
    troubles = Trouble.objects.all()
    return render(request, 'report_fault/home.html', {
        'troubles': troubles,
        'user_form': user_form,
    })
Exemplo n.º 23
0
def login(request):
	if request.method == 'POST':
		uf = UserForm(request.POST)
		if uf.is_valid():
			username = uf.cleaned_data['username']
			password = hashlib.sha1(uf.cleaned_data['password']+username).hexdigest()
			try:
				UserModel.objects.get(username=username,password=password)
				response = HttpResponseRedirect('/index/')
				response.set_cookie(key='username',value=username)
				return response
			except ObjectDoesNotExist:
				return HttpResponseRedirect('/login/')
	else:
		uf = UserForm()
	return render(request,'login.html',{'uf':uf})
Exemplo n.º 24
0
def register(request):
    if request.method == 'POST':
        form = UserForm(request.POST, request.FILES)
        if form.is_valid():
            name = form.cleaned_data['username']
            pw = form.cleaned_data['password']
            newuser = User.objects.create_user(name, form.cleaned_data['email'], pw)
            newuser.save()
            profile = Profile.objects.create(user = newuser)
            profile.save()
            user = authenticate(username = name, password = pw)
            auth_login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = UserForm()
    return render_to_response("register.html", {'form':form})
Exemplo n.º 25
0
def register(request):
	if request.method == 'POST':

		uf = UserForm(request.POST, request.FILES)
		if uf.is_valid():
			um = UserModel()
			um.username = uf.cleaned_data['username']
			um.password = hashlib.sha1(uf.cleaned_data['username']+uf.cleaned_data['password']).hexdigest()
			um.email	= uf.cleaned_data['email']
			um.birthday = uf.cleaned_data['birthday']
			um.headimg	= uf.cleaned_data['headimg']
			um.descript = uf.cleaned_data['descript']
			um.save()
			return HttpResponse('ok')
	else:
		uf = UserForm()
	return render(request,'register.html',{'uf':uf})
Exemplo n.º 26
0
def register(request):
    tagss = Tag.objects.all()
    posts = Post.objects.order_by('-created_date')
   
    for tag in tagss:
       q = Post.objects.filter(tags=tag)
       z = q.count()>2
       if z:
          x=True
          tag.important=x
          tag.save()
    tags=Tag.objects.filter(important=True)
    # 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':

        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()
            registered = True                  
        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render_to_response(
            'blog/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered,'tags':tags},
            context)
Exemplo n.º 27
0
def login(request):
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user_id = form.cleaned_data['user_id']
            password = form.cleaned_data['password']
            user = models.User.objects.filter(user_id__exact=user_id,
                                              password__exact=password)
            if user:
                print('登录成功')
                articles = models.Article.objects.all()
                return redirect('/blog/index', {'articles': articles})
            else:
                return HttpResponse("登录ID或密码错误<a href='/blog/login'>登录</a>")

    else:
        form = UserForm().as_ul()
    return render(request, 'blog/login.html', {'form': form})
Exemplo n.º 28
0
def regist(req):
	if req.method == "POST":
		uf = UserForm(req.POST,req.FILES)
		if uf.is_valid():	#valid验证
			username = uf.cleaned_data['username']
			password = uf.cleaned_data['password']	#收集到的数据
			email = uf.cleaned_data['email']
			birthday = uf.cleaned_data['birthday']
			sex = uf.cleaned_data['sex']
			headimg = uf.cleaned_data['headimg']
			text = uf.cleaned_data['text']

			passwd = hashlib.sha1(username+password).hexdigest()
			Regist.objects.create(username=username,password=passwd,email=email,birthday=birthday,sex=sex,headimg=headimg,text=text)
			return HttpResponse('ok')
	else:
		uf = UserForm()
	return render(req,'regist.html',{'uf':uf})
Exemplo n.º 29
0
def login(request):

	if request.method == 'POST':
		# username = request.POST['username']
		# password = request.POST['password']
		uf = UserForm(request.POST)
		if uf.is_valid():
			username = uf.instance.username
			password = uf.instance.password
			password = hashlib.sha1(username+password).hexdigest()
			try:
				User.objects.get(username=username,password=password)
				response = HttpResponseRedirect('/index/')
				response.set_cookie(key='username',value=username)
				return response
			except ObjectDoesNotExist:
				print "not found"

	return render(request,'login.html',{})
Exemplo n.º 30
0
def register(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))
          registered=True
          # login
          user.backend="django.contrib.auth.backends.ModelBackend"
          login(request, user)
       else:
           print user_form.errors
    else:
        user_form=UserForm()
    return render_to_response('blog/register.html',
                          {'user_form':user_form, 'registered':registered},
                          context)
Exemplo n.º 31
0
def register(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
    else:
      print user_form.error
  else:
    user_form = UserForm()

  return render_to_response(
          'blog/register.html', 
          {'user_form': user_form, 'registered': registered}, 
          context)
Exemplo n.º 32
0
def register_view(request):
    context = {}
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            user = auth.authenticate(username=username, password=password)
            if user:
                context['userExit'] = True
                return render(request, 'blog/index.html', context)
            user = User.objects.create_user(username=username, password=password)
            user.save()
            request.session['username'] = username
            auth.login(request, user)
            return HttpResponseRedirect('/index')
    else:
        context = {'isLogin': False}

    return render(request, 'blog/register.html', context)
Exemplo n.º 33
0
    def post(self, request):
        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 sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            profile = profile_form.save(commit=False)
            profile.user = user
            # Now we save the UserProfile model instance.
            profile.save()
            return redirect('/')
        else:
            context = {
                'user_form': user_form,
                'profile_form': profile_form
            }
            return render(request, self.template, context)
Exemplo n.º 34
0
def register_votant(request):
    register = False
    if request.method == 'POST':

        user_form = UserForm(data=request.POST)
        profile_form = VotantForm(data=request.POST)

        # If the two forms are valid...
        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()
            register = True
        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = VotantForm()
    return render(request,
                  'registerV.html',
                  {'user_form': user_form, 'profile_form': profile_form, 'register': register})
Exemplo n.º 35
0
def register_condidate(request):
    if request.method == 'POST':
        register = False
        date = False
        event = evenement.objects.get(id=int(request.POST["evenement"]))
        date = test(event.date_fin_register)
        user_form = UserForm(data=request.POST)
        profile_form = CondidateForm(data=request.POST)

        # If the two forms are valid...
        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 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            profile.save()
            register = True
        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = CondidateForm()
    return render(request,
                  'registerC.html',
                  locals(),)
Exemplo n.º 36
0
def register(request):
    if request.method == "POST":
        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()
            # Hash password
            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()
            login(request, user)
            return HttpResponseRedirect(reverse('blog:post_list'))
        else:
            print(user_form.errors, profile_form.errors)
            return render(request, "registration/register.html", {
                'user_form': user_form,
                'profile_form': profile_form
            })
    else:
        if request.user.is_authenticated:
            return redirect("/")

        user_form = UserForm()
        profile_form = UserProfileForm()
        return render(request, "registration/register.html", {
            'user_form': user_form,
            'profile_form': profile_form
        })
Exemplo n.º 37
0
def register(request):
    registered = False
    if request.session.has_key('username'):
        username = request.session['username']
        return render(request, 'blog/index.html')
    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()
    if registered:
        return render(request, 'blog/login.html')
    return render(
        request, 'blog/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 38
0
def register(request):
    if request.method == "GET":
        user_form = UserForm()
        user_profile_form = UserProfileForm()
        context = {
            'user_form': user_form,
            'user_profile_form': user_profile_form,
        }
        return render(request, "blog/register.html", context)
    if request.method == "POST":

        user_form = UserForm(request.POST)
        user_profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and user_profile_form.is_valid():

            user_object = user_form.save()

            user_profile_object = user_profile_form.save(commit=False)

            user_profile_object.user = user_object

            user_profile_object.save()

        else:
            pass

        return redirect('blog:index')
Exemplo n.º 39
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()
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm(data=request.GET)
    return render(
        request, 'blog/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 40
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:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
            return redirect('/blog/login')
        else:
            print(user_form.errors,profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(request,'blog/Inscription.html',
                          {'user_form':user_form,
                           'profile_form':profile_form,
                           'registered':registered})
Exemplo n.º 41
0
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()
            #profile= profile_form.save(commit=False)
            #profile.user=user
            #profile.save()

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

        user_form = UserForm()
        #profile_form = UserProfileInfoForm()

    return render(request, 'registration/registration.html', {
        'user_form': user_form,
        'registered': registered,
    })
Exemplo n.º 42
0
def sign_up(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(
        ) and request.recaptcha_is_valid:
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'photo' in request.FILES:
                print('found it')
                profile.photo = request.FILES['photo']
            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'blog/sign_up.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemplo n.º 43
0
def register(request):
    if request.method=='POST':
        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("/blog/")

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

    return render(request,
        'blog/register.html',
        {'user_form': user_form, 'profile_form': profile_form } )
Exemplo n.º 44
0
def login_view(request):
    context = {}
    print('login')
    if request.method == "POST":
        form = UserForm(request.POST)
        print(form)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            user = auth.authenticate(username=username, password=password)
            if user:
                auth.login(request, user)
                request.session['username'] = username
                return HttpResponseRedirect('/index/')
            else:
                context = {'isLogin': False, 'pawd': False}
                return render(request, 'blog/login.html', context)
    else:
        context = {'isLogin': False, 'pawd': True}

    return render(request, 'blog/login.html', context)
Exemplo n.º 45
0
def regist(request):
    if request.method == 'POST':
        form = UserForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponse('注册成功')
        else:
            return HttpResponse(form.errors)
    else:
        form = UserForm()
    return render(request, 'regist.html', {'form': form})
Exemplo n.º 46
0
def register(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)
			user.save()
			registered = True

		else:
			print user_form.errors

	else:
		user_form = UserForm()

	context = {
		'user_form': user_form,
		'registered': registered
	}

	return render(request, 'registration/register.html', context)		
Exemplo n.º 47
0
def register(request):
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        user_info_form = UserInfoForm(data=request.POST)
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            user_profile = user_info_form.save(commit=False)
            user_profile.user = user
            user_profile.save()
            registered = True
            data_set = dict(username=str(user_form['username'].value()), email=str(user_form['email'].value()),
                            registered=registered)
            json_response = json.dumps(data_set)
            return HttpResponse(json_response)
        else:
            data_set = dict(detail="User Exists Or Form Have Invalid Failed/s.")
            json_response = json.dumps(data_set)
            return HttpResponseBadRequest(json_response)
    else:
        data_set = dict(detail="Bad request.")
        json_response = json.dumps(data_set)
        return HttpResponseBadRequest(json_response)
Exemplo n.º 48
0
def sign_in(request):
    context = {'form': UserForm()}
    if request.method == 'GET':
        return render(request, 'sign_in.html', context=context)

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        # user = authenticate(username='******', password='******')
        if user is not None:
            login(request, user)

            posts = Post.objects.filter(author=request.user)
            return redirect('posts_list')
        else:
            messages.error(request, 'Incorrect username/password.')
            return render(request, 'sign_in.html', context=context)
Exemplo n.º 49
0
def register(request):
    tagss = Tag.objects.all()
    posts = Post.objects.order_by('-created_date')

    for tag in tagss:
        q = Post.objects.filter(tags=tag)
        z = q.count() > 2
        if z:
            x = True
            tag.important = x
            tag.save()
    tags = Tag.objects.filter(important=True)
    # 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':

        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()
            registered = True
        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render_to_response(
        'blog/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
            'tags': tags
        }, context)
Exemplo n.º 50
0
def update_profile(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request,
                             "'Your profile was successfully updated!'")
            return redirect('profile', user_id=request.user.id)
        else:
            messages.error(request, "Please correct the error below.'")
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'profiles/profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Exemplo n.º 51
0
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, 'register.html', {
        'user_form': user_form,
        'registered': registered
    })
Exemplo n.º 52
0
    def post(self, request, *args, **kwargs):
        # import pdb; pdb.set_trace() #  дебаггер
        form = UserForm(request.POST, request.FILES)
        form.is_valid()
        form.save()
        return self.get(request, *args, **kwargs)


# def article(request):
#     articles = Article.objects.all()
#     return render(request, "articles.html", context={'title': 'Articles', 'articles': articles})

# class ArticleListView(ListView):
#     model = Article
#     template_name = 'articles.html'
#
#     def get_context_data(self, *, object_list=None, **kwargs):
#         context = super().get_context_data(object_list=None, **kwargs)
#         context['articles'] = self.object_list
#         context['form'] = ArticleForm
#         return context
#
#     def post(self, request, *args, **kwargs):
#         # import pdb; pdb.set_trace() #  дебаггер
#         form = ArticleForm(request.POST)
#         form.is_valid()
#         form.save()
#         return self.get(request, *args, **kwargs)

# def home(request):
#     users = User.objects.all()
#     return render(request, "main.html", context={'users': users, 'form': ArticleForm()})

# def get_user(request, username):
#     return render(request, 'user.html', context={
#         'user': User.objects.get(username=username)
#     })
#

# def create_comment(request):
#     if request.POST:
#         Comment.object.create(
#             text=request.POST.get('text')
#         )
#     return render(request, 'create_comment.html')
Exemplo n.º 53
0
def register(request):
    if not request.session.get('username'):
        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)

            # Check to see both forms are valid
            if user_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()

                # Registration Successful!
                registered = True
                login(request, user)
                request.session['username'] = user.username

                return HttpResponseRedirect(reverse('user_login'))

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

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

        # This is the render and context dictionary to feed
        # back to the registration.html file page.
        return render(request, 'sign_up.html', {
            'user_form': user_form,
            'registered': registered
        })
    return HttpResponseRedirect(reverse('mainpageloggedin'))
Exemplo n.º 54
0
def user_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
            login(request, user)
            return HttpResponseRedirect(reverse('post_list'))
        else:
            print(user_form.errors)
    else:
        user_form = UserForm()

    return render(request, "registration/registration.html", {'registered': registered, 'form': user_form})
Exemplo n.º 55
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():

			print("VALIDATION SUCCESS")
			print(f"Username: {user_form.cleaned_data['username']}")
			print(f"First Name: {user_form.cleaned_data['first_name']}")
			print(f"Last Name: {user_form.cleaned_data['last_name']}")
			print(f"Email: {user_form.cleaned_data['email']}")
			print(f"Password: {user_form.cleaned_data['password']}")

			user = user_form.save()
			user.set_password(user.password)
			user.save()

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

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

			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})