Ejemplo n.º 1
0
def register(request):
    form = forms.NewUserForm()
    if request.POST:
        ensure_permissions()
        form = forms.NewUserForm(request.POST)
        role = request.POST.get('role')
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = User.objects.create_user(username=username, password=password)
            if role is not None:
                if have_permission(request, ['blog.can_add', 'blog.can_edit_schedule']):
                    if role == 'is_admin' or role == 'is_cashier':
                        if role == 'is_admin':
                            permission = Permission.objects.get(codename='can_add')
                        elif role == 'is_cashier':
                            permission = Permission.objects.get(codename='can_edit_schedule')
                    else:
                        user.delete()
                        return redirect('no_permission')
                    e = UserProfile()
                    e.profile = user
                    e.author = request.user
                    e.save()
                    user.user_permissions.add(permission)
                    user.save()
            if request.user.has_perm('blog.can_add') or request.user.has_perm('blog.can_edit_schedule'):
                return redirect('users.html')
            else:
                return redirect('login.html')
    perm = have_permission(request, ['blog.can_add', 'blog.can_edit_scheduele'])
    return render(request, 'register.html', {'form': form, 'perm': perm})
Ejemplo n.º 2
0
 def registration(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     data = json.loads(request.body)
     try:
         email = data.get('email')
         password = data.get('password')
         confirm_password = data.get('confirm_password')
         phone_number = data.get('phone_number')
     except KeyError:
         return self.create_response(request, {}, HttpBadRequest)
     first_name = data.get('first_name', '')
     last_name = data.get('last_name', '')
     try:
         User.objects.get(username=email)
         return self.create_response(request, {}, HttpBadRequest)
     except ObjectDoesNotExist:
         if password == confirm_password:
             user = User.objects.create_user(email, email, password,
                 first_name=first_name, last_name=last_name)
             user.save()
             user_profile = UserProfile(user=user, phone_number=phone_number)
             try:
                 user_profile.save()
             except:
                 user.delete()
                 return self.create_response(request, {}, HttpBadRequest)
             return self.create_response(request, {})
         else:
             return self.create_response(request, {}, HttpBadRequest)
Ejemplo n.º 3
0
def register_view(request):
    error = None
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']

            if User.objects.filter(username=username).exists():
                error = 'Username already exist'
            else:
                User.objects.create_user(username=username,
                                         password=password)
                user = authenticate(username=username, password=password)
                login(request, user)
                profile = UserProfile(user=user, email='', preferences='')
                profile.save()
                #return HttpResponseRedirect(reverse('events:events_page', args=(1,)))          установка параметров
                return HttpResponseRedirect(reverse('media:index'))
    else:
        form = UserCreationForm()

    return render(request, 'authentication/register.html', {'form': form, 'error': error})
Ejemplo n.º 4
0
def newusercap(request,utype,password,email,capadminid):
	print "newusercap"
	response={}
	if request.method == "POST":
		user=authenticate(username=email, password=password)
		if user is not None:
			if not user.is_active:
				print "User is registering"
				first_name=request.POST['first_name']
				password=request.POST['password']
				conpassword=request.POST['conpassword']
				if password == conpassword:
					user.set_password(password)
					user.first_name=first_name
					user.is_active=True
					user.save()
					userp=UserProfile()
					userp.user=user
					userp.collegeName=request.POST['collegeName']
					userp.phone=request.POST['telephone']
					userp.description=request.POST['description']
					userp.usertype=utype
					if request.FILES['picture']:
						userp.profilepicture=request.FILES['picture']
					else:
						userp.profilepicture='default.jpg'
					userp.lastLoginDate=datetime.now()
					userp.save()
					cap=CapMember()
					cap.capadmin=User.objects.get(id=capadminid)
					cap.capmember=user
					cap.save()
					return HttpResponseRedirect('/login')
				else:
					response['message']="Password not matching"
			else:
				response['message']='User already active'
		else:
			response['message']='User is not allowed to be registered'
	response['utype']=utype
	response['password']=password
	response['email']=email
	response['capadminid']=capadminid
	response['capadmin']=User.objects.get(id=capadminid)
	return render(request,'site/registernewuser.html',response)
Ejemplo n.º 5
0
def newuser(request,utype,password,email):
	response={}
	if request.method == "POST":
		user=authenticate(username=email, password=password)
		if user is not None:
			if not user.is_active:
				print "User is registering"
				first_name=request.POST['first_name']
				password=request.POST['password']
				conpassword=request.POST['conpassword']
				if password == conpassword:
					user.set_password(password)
					user.first_name=first_name
					user.is_active=True
					user.save()
					userp=UserProfile()
					userp.user=user
					userp.collegeName=request.POST['collegeName']
					userp.phone=request.POST['telephone']
					userp.description=request.POST['description']
					userp.usertype=utype
					if request.FILES['picture']:
						userp.profilepicture=request.FILES['picture']
					else:
						userp.profilepicture='default.jpg'
					userp.lastLoginDate=datetime.now()
					userp.save()
					if utype == 'Organisation':
						org=Organisation()
						org.user=user
						org.name=request.POST['first_name']
						org.description=request.POST['description']
						if request.FILES['picture']:
							org.logo=request.FILES['picture']
						else:
							org.logo='default.jpg'
						org.address=request.POST['address']
						org.save()
					return HttpResponseRedirect('/login')
				else:
					response['message']="Password not matching"
			else:
				response['message']='User already active'
		else:
			response['message']='User is not allowed to be registered'
	response['utype']=utype
	response['password']=password
	response['email']=email
	return render(request,'site/registernewuser.html',response)