Exemplo n.º 1
0
def create_user_view(request):
    if request.method == 'GET':
        form = CreateUserForm()
        return render(request, 'create_user.html', {'form': form})
    elif request.method == 'POST':
        form = CreateUserForm(request.POST)

        if form.is_valid():
            email = form.cleaned_data['email_address']
            password = form.cleaned_data['password']
            confirm_password = form.cleaned_data['password_repeat']

            if password == confirm_password:
                # check if user exists
                user = User.objects.filter(username=email).first()
                if not user:
                    new_user = User.objects.create_user(username=email,
                                                        email=email,
                                                        password=password)
                    new_user.save()
                    return HttpResponseRedirect('/home')
                else:
                    error = {'msg': 'Account already exists'}
                    return render(request, 'create_user.html', {
                        'form': form,
                        'error': error
                    })
            else:
                error = {'msg': 'Passwords are not the same'}
                return render(request, 'create_user.html', {
                    'form': form,
                    'error': error
                })
Exemplo n.º 2
0
def register(request):
    next = request.REQUEST.get('next', '')
    if request.method == 'POST':
        form = CreateUserForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            UserProfile.objects.create(user=new_user)
            new_user = authenticate(username=new_user.username, password=request.POST['password1'])
            print new_user
            if new_user is not None and new_user.is_active:
                login(request, new_user)
            return HttpResponseRedirect(request.POST['next'])
    else:
        form = CreateUserForm()
    return render_to_response("registration/register.html", locals(), context_instance=RequestContext(request))
Exemplo n.º 3
0
def add_user(request):
	if request.POST:
		form = CreateUserForm(request.POST)
		if form.is_valid():
			username = form.cleaned_data['username']
			password = form.cleaned_data['password1']
			user = User.objects.create_user(username)
			user.set_password(password)
			user.save()
			messages.add_message(request, messages.INFO, "User . "+username+" Addeded Sucessfully")
			return HttpResponseRedirect(reverse('dashboard'))
	else:
		form = CreateUserForm()
	base_template = 'dashboard.html'
	return render(request,'fileupload/add_user.html',{'form':form, 'base_template':base_template })
Exemplo n.º 4
0
def add_user_fancy(request):
	if request.POST:
		form = CreateUserForm(request.POST)
		if form.is_valid():
			username = form.cleaned_data['username']
			password = form.cleaned_data['password1']
			user = User.objects.create_user(username)
			user.set_password(password)
			user.save()
			form = CreateUserForm()
			base_template = 'fancy.html'
			return render(request,'fileupload/add_user_fancy.html',
			{'form':form, 'base_template':base_template ,'message':"User "+user.username+" Added Sucessfully"})
	else:
		form = CreateUserForm()
	base_template = 'fancy.html'
	return render(request,'fileupload/add_user_fancy.html',{'form':form, 'base_template':base_template })
Exemplo n.º 5
0
def createuser(request):
    if request.method == 'POST':
        form = CreateUserForm(request.POST)
        if form.is_valid():
            firstname = form.cleaned_data['firstname']
            lastname = form.cleaned_data['lastname']
            email = form.cleaned_data['email']
            username = form.cleaned_data['username'].lower()
            password = form.cleaned_data['password']
            if User.objects.filter(username=username).exists():
                return HttpResponse('User %s already exists' % username)
            User.objects.create_user(username, email, password, first_name=firstname, last_name=lastname)
            return HttpResponse('User %s Created<br /><a href="/auth/">return</a>' % username)
    else:
        form = CreateUserForm()
        context = {'form':form}
        return render(request, 'auth/createuser.html', context)
Exemplo n.º 6
0
def register(request):
    next = request.REQUEST.get('next', '')
    if request.method == 'POST':
        form = CreateUserForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            UserProfile.objects.create(user=new_user)
            new_user = authenticate(username=new_user.username,
                                    password=request.POST['password1'])
            print new_user
            if new_user is not None and new_user.is_active:
                login(request, new_user)
            return HttpResponseRedirect(request.POST['next'])
    else:
        form = CreateUserForm()
    return render_to_response("registration/register.html",
                              locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 7
0
def create_user(request, activate_key):
    try:
        key = ActivateKey.objects.get(activate_key=activate_key, activated=False)
    except ActivateKey.DoesNotExist:
        raise Http404()
    if request.method == 'POST':
        form = CreateUserForm(request.POST)
        if form.is_valid():
            u = form.save(commit=False)
            u.set_password(form.cleaned_data.get('password'))
            u.save()
            key.activated = True
            key.save()
            set_snsuser_message(request,
                _(u"Create Your account. You can logged in now."))
            return HttpResponseRedirect(reverse('index'))
    else:
        form = CreateUserForm(initial={'email': key.belongs_to_email})
    return render_to_response('snsuser/snsuser_form.html', context_instance=RequestContext(request, {'form': form}))
Exemplo n.º 8
0
    def post(self, request, *args, **kwargs):
        form = CreateUserForm(request.POST)
        if form.is_valid():
            user = User(username=form.cleaned_data['username'])
            user.set_password(form.cleaned_data['password'])
            user.is_staff = (form.cleaned_data['user_role'] == 'dealer')
            user.is_active = True
            user.save()

            user_profile = UserProfile()
            user_profile.user = user
            user_profile.notes = form.cleaned_data['notes']
            user_profile.comission = form.cleaned_data['comission']
            if not user.is_staff:
                dealer = User.objects.get(
                    pk=form.cleaned_data['select_dealer'])
                user_profile.dealer = dealer
                user_profile.open_password = form.cleaned_data['password']
            user_profile.save()

        return HttpResponseRedirect('/user_list.html')
Exemplo n.º 9
0
def sign_up(request):
	context = {}
	context['form'] = CreateUserForm()

	if request.method == 'POST':
		form = CreateUserForm(request.POST)
		context['form'] == form
		if  form.is_valid():
			username = form.cleaned_data['username']
			password = form.cleaned_data['password']
			email = form.cleaned_data['email']
			#print username
			new_user = User.objects.create_user(username=username, password=password)
			new_user.save()
			
			auth_user = authenticate(username=username, password=password)
			login(request, auth_user)

			return redirect('/countrylist/')

	return render(request, 'sign_up.html', context)
Exemplo n.º 10
0
def createUser(request):
    if request.method == 'POST':
        form =CreateUserForm(request.POST)
        if form.is_valid():
            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"]

            user = User.objects.create_user(username, email, password)
            user.first_name = first_name
            user.last_name = last_name

            user.save()

            return HttpResponseRedirect("/yaas/loginuser/")
    else:
        form =CreateUserForm()

    return render_to_response("newUser.html", {'form': form},context_instance= RequestContext(request))
Exemplo n.º 11
0
def createUser(request):
    if request.method == 'POST':
        form = CreateUserForm(request.POST)
        if form.is_valid():
            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"]

            user = User.objects.create_user(username, email, password)
            user.first_name = first_name
            user.last_name = last_name

            user.save()

            return HttpResponseRedirect("/yaas/loginuser/")
    else:
        form = CreateUserForm()

    return render_to_response("newUser.html", {'form': form},
                              context_instance=RequestContext(request))
Exemplo n.º 12
0
def resolve(request):
    def _extract(d, keys):
        return dict((k, d[k]) for k in keys if k in d)

    workflow = get_workflow(request)

    if not workflow.is_authenticated():
        return redirect("/")

    if request.user.is_authenticated():
        workflow.associate_user(request, request.user)
        return login_ok_redirect()

    create_user_form = CreateUserForm(request.POST or None, initial=workflow.get_session().me())
    login_form = AuthenticationForm(request, request.POST or None)

    if create_user_form.is_valid():
        workflow.create_user(
            request,
            **(_extract(create_user_form.cleaned_data, [
                'username',
                'password',
                'first_name',
                'last_name',
                'email'])))
        return login_ok_redirect()
    
    elif login_form.is_valid():
        user = authenticate(username=login_form.cleaned_data['username'], password=login_form.cleaned_data['password'])
        if user and user.is_active:
            workflow.associate_user(request, user)
            login(request, user)
            return login_ok_redirect()
    
    else:
        request.session.set_test_cookie()

    return render(request, "resolve/resolve.html", dict(create_user_form=create_user_form, login_form=login_form))
Exemplo n.º 13
0
def sign_up(request):
	context={}							# make context empty
	context['form']=CreateUserForm()	# Copy CreateUserForm to form inside context

	if request.method=='POST':			# only work when user submit some input to website (2nd time)
		form=CreateUserForm(request.POST)	# copy form (2nd website or POST is true) to form (variable)
		context['formn']=form 				# copy the form variable to our context

		if form.is_valid():
			username=form.cleaned_data['username']
			email=form.cleaned_data['email']
			password=form.cleaned_data['password1']

			new_user=User.objects.create_user(username=username, password=password, email=email)
			new_user.save()

			# To let the user automatic login after succeful sign Up
			auth_user=authenticate(username=username, password=password, email=email)	# Check username and password from database then copy to auth_user
			login(request, auth_user)

			return redirect('/countrylist/')	# Redirect to URL after automatic login

	return render(request,'sign_up.html',context)	# Only will work when first time open the URL (GET)
Exemplo n.º 14
0
def create(request):
    """
    show a form for user registration
    """
    if request.method == 'POST':
        # arriving data to process
        form = CreateUserForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            
            if data['password1'] != data['password2']:
                return django.shortcuts.render_to_response('create_form.html',
                                                   {'form': form, 'error_message': 'The two versions of your password differed!'},
                                                   context_instance=django.template.RequestContext(request))
            
            hashed_password = django.contrib.auth.hashers.make_password(data['password1'])
            user = django.contrib.auth.models.User(username=data['nick'],
                                                   first_name=data['firstname'],
                                                   last_name=data['lastname'],
                                                   email=data['email'],
                                                   password=hashed_password)
            user.save()
            user.userprofile.sex = data['sex']
            user.userprofile.save()
            
            return django.shortcuts.redirect('homepage.views.home') # todo: redirect to the login page
        else:
            return django.shortcuts.render_to_response('create_form.html',
                                                   {'form': form, 'error_message': 'Input invalid.'},
                                                   context_instance=django.template.RequestContext(request))
    else:
        # show an empty form 
        form = CreateUserForm()
        return django.shortcuts.render_to_response('create_form.html',
                                                   {'form': form},
                                                   context_instance=django.template.RequestContext(request))