Ejemplo n.º 1
0
 def post(self, request):
     form = SignUpForm(data=request.POST)
     print(form.is_valid())
     if form.is_valid():
         first_name = form.cleaned_data['first_name']
         last_name = form.cleaned_data['last_name']
         login_name = form.cleaned_data['login']
         email_field = form.cleaned_data['email']
         password1 = form.cleaned_data['password1']
         password2 = form.cleaned_data['password2']
         if password1 == password2:
             #Create a new user
             print(login_name)
             user = User.objects.create_user(first_name=first_name,
                                             last_name=last_name,
                                             username=login_name,
                                             password=password1,
                                             email=email_field)
             id_number = user.id
             user.save()
             #Relate the new user with the Parent model
             print(id_number)
             #parent = Parent.objects.create(parent_id=id_number)
             #parent.add(user)
             #parent.save()
             return HttpResponse("New user added")
         else:
             return HttpResponse("Passwords aren't identical")
     return HttpResponse('Data is not valid')
def signup(request):
    if request.method == 'POST':

        #  Check whether the data is valid or not.
        form = SignUpForm(request.POST)
        if form.is_valid():

            username = request.POST.get('username', '')
            email = request.POST.get('email', '')
            password = request.POST.get('password', '')
            is_admin = request.POST.get('is_admin', '')

            #  Create the user in the database.
            user = User.objects.create_user(username=username,
                                            email=email,
                                            password=password,
                                            is_staff=is_admin,
                                            is_superuser=is_admin)

            #  Get the user's data.
            data = {
                'id': user.id,
                'username': user.username,
                'email': user.email,
                'admin': user.is_superuser
            }
            return JsonResponse(data)

        #  Return invalid fields.
        else:
            return JsonResponse(form.errors)
    else:
        return JsonResponse("Method " + request.method + " not allowed",
                            safe=False)
Ejemplo n.º 3
0
 def setUp(self):
     self.username = '******'
     self.email = '*****@*****.**'
     self.password = '******'
     self.myForm = SignUpForm({
         'username': self.username,
         'email': self.email,
         'password': self.password})
Ejemplo n.º 4
0
    def post(self, request):
        form = SignUpForm(request.POST, request.FILES)

        if form.is_valid():
            profile = form.save()
            login(request, profile.user)
            return redirect(reverse('main:root'))

        return render(request, 'main/sign_up.html', context={'form': form, 'user': request.user})
    def put(request, user_id):
        if user_id is not None:
            try:
                user = User.objects.get(pk=user_id)
            except User.DoesNotExist:
                return JsonResponse("User doesn't exist", safe=False)

            #  If any of these parameters exist in the request object, the corresponding attributes values
            #  of the found user will be replaced with them.
            if 'username' in request.PUT:
                user.username = request.PUT["username"]

            if 'email' in request.PUT:
                user.email = request.PUT["email"]

            #  Check whether password parameter exist in the request,
            #  if it does, check if it's valid and encrypt it when affecting to the user.
            if 'password' in request.PUT:
                password = request.PUT["password"]
                if len(password) > 7:
                    user.set_password(request.PUT["password"])
                else:
                    return JsonResponse("Invalid password", safe=False)

            if 'is_admin' in request.PUT:
                is_admin = request.PUT["is_admin"]
                user.is_superuser = is_admin

                print(user.is_superuser)
                user.is_staff = is_admin

            #  Check if the data in the user instance is valid,
            #  if it's valid, update the user in the database.
            user_form = SignUpForm(
                {
                    'username': user.username,
                    'email': user.email,
                    'password': user.password,
                    'is_superuser': user.is_superuser
                },
                instance=user)
            if user_form.is_valid():
                user.save()
                data = {
                    'username': user.username,
                    'email': user.email,
                    'is_admin': user.is_superuser,
                    'password': user.password
                }
                return JsonResponse(data)
            else:
                return JsonResponse(user_form.errors)
        else:
            return JsonResponse("User id not provided", safe=False)
Ejemplo n.º 6
0
    def post(self, request):
        if request.user.is_authenticated:
            return redirect('dashboard_index_url')

        year = datetime.datetime.now().year
        bound_form = SignUpForm(request.POST)

        if bound_form.is_valid():
            new_user = bound_form.save()
            return redirect('dashboard_index_url')
        else:
            return render(request, 'main/sign-up.html', context={'form': bound_form, 'current_year': year})
Ejemplo n.º 7
0
def signup(request):
    form = SignUpForm(request.POST or None)
    if form.is_valid():
        new_user = form.save()
        new_user = authenticate(username=request.POST['username'], 
                                password=request.POST['password1'])
        user = authenticate(user=new_user, password=request.POST['password1'])
        login(request, new_user)
        return HttpResponseRedirect('/accounts/create/')

    data = {'title': 'Kolabria - Create an Account', 'form': form,}
    return render_to_response('main/simple.html', data, 
                              context_instance=RequestContext(request))
Ejemplo n.º 8
0
def renderUserResourceLists(request, username):
    returns = {
        "jsonResourceLists": "[]",
        "jsonBookmarks": "[]",
        "jsonProfile": ""
    }
    if request.user.is_authenticated is False:
        returns['SignUpForm'] = SignUpForm()

    user = get_object_or_404(User, username=username)
    returns["user"] = user

    # jsonResourceLists
    if (request.user.is_authenticated and request.user == user):
        returns["jsonResourceLists"] = jsonModels.getResourceLists(
            user=user, order_by="-updatedAt")
    else:
        returns["jsonResourceLists"] = jsonModels.getResourceLists(
            user=user, isPublic=True, order_by="-updatedAt")

    # jsonBookmarks
    if (request.user.is_authenticated):
        returns["jsonBookmarks"] = jsonModels.getBookmarks(user=request.user)
    returns["jsonProfile"] = serialize('json', [user.profile])
    return render(request, 'user/userLists.html', returns)
Ejemplo n.º 9
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = SignUpForm()
    if form.validate_on_submit():
        hashPassword = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashPassword)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.username.data}! Now you can login',
              'success')
        return redirect(url_for('login'))
    return render_template('signup.html', form=form, title="SignUp")
Ejemplo n.º 10
0
    def get(self, request):
        if request.user.is_authenticated:
            return redirect('dashboard_index_url')

        year = datetime.datetime.now().year
        form = SignUpForm()

        return render(request, 'main/sign-up.html', context={'form': form, 'current_year': year})
Ejemplo n.º 11
0
def SignUp():
    if current_user.is_authenticated:
        flash("You are already logged in", 'warning')
        return redirect(url_for('home'))
    form = SignUpForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pw)
        db.session.add(user)
        db.session.commit()
        flash(f'Account Created for {form.username.data}! You can now log in',
              'success')
        return redirect(url_for('Login'))
    return render_template('signUp.html', form=form, title='Sign Up')
Ejemplo n.º 12
0
def signup_view(request):

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

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

            User.objects.create_user(username, email, password)

            return HttpResponseRedirect('/thanks/')
    else:
        form = SignUpForm()

    return render(request, 'signup.html', {'form': form})
Ejemplo n.º 13
0
def signup(request,ligaId):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            if nombreValido(form.cleaned_data.get('username')):
                form.save()
                username = form.cleaned_data.get('username')
                userr=User.objects.get(username=username)
                liga=Liga.objects.get(idLiga=form.cleaned_data.get('idLiga'))
                if liga.estrategiaLiga=='1':
                    pres=40000000
                else:
                    pres=20000000
                user=Usuario.objects.create(user=userr,presupuesto=pres,liga=liga)
                Alineacion.objects.create(tipoAlineacion='E',usuarios=user)
                if liga.estrategiaLiga=='2':
                    add_jugadores(user,liga)
                
                raw_password = form.cleaned_data.get('password1')
                user = authenticate(username=username, password=raw_password)
                login(request, user)
                
                #Falta crear usuario con ese user pero depende del tipo de liga
                l=reverse('alineacionList')
                print(l)
                return HttpResponseRedirect(l)
    else:
        form = SignUpForm({'idLiga':ligaId})
    return render_to_response('signup.html', {'form': form},context_instance=RequestContext(request))
Ejemplo n.º 14
0
def signup(request):
    # if this is a POST request we need to process the form data
    template = 'main/register.html'

    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = SignUpForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            if User.objects.filter(
                    username=form.cleaned_data['username']).exists():
                return render(request, template, {
                    'form': form,
                    'error_message': 'Юзернейм уже существует!.'
                })
            elif form.cleaned_data['password'] != form.cleaned_data[
                    'password_repeat']:
                return render(request, template, {
                    'form': form,
                    'error_message': 'Пароли не совпадают.'
                })
            else:
                # Create the user:
                user = User.objects.create_user(
                    form.cleaned_data['username'], )
                user.set_password(form.cleaned_data['password'])
                user.email = form.cleaned_data['email']
                user.first_name = form.cleaned_data['first_name']
                user.last_name = form.cleaned_data['last_name']
                user.phone_number = form.cleaned_data['phone']
                user.profile.passport = form.cleaned_data['passport']
                user.save()

                # Login the user
                login(request, user)

                # redirect to accounts page:
                return HttpResponseRedirect('home')

    # No post data availabe, let's just show the page.
    else:
        form = SignUpForm()

    return render(request, template, {'form': form})
Ejemplo n.º 15
0
def renderSearch(request):
    returns = {}
    if request.user.is_authenticated is False:
        returns['SignUpForm'] = SignUpForm()
    resourceLists = ResourceList.objects.filter(
        title__icontains=request.GET['q'])
    returns["jsonResourceLists"] = serialize('json',
                                             resourceLists,
                                             use_natural_foreign_keys=True)
    return render(request, 'index.html', returns)
Ejemplo n.º 16
0
def renderIndex(request):
    returns = {}
    returns["jsonResourceLists"] = jsonModels.getResourceLists(
        isPublic=True, order_by="-updatedAt")

    if request.user.is_authenticated:
        returns["jsonBookmarks"] = jsonModels.getBookmarks(user=request.user)
    else:
        returns['SignUpForm'] = SignUpForm()

    return render(request, 'index.html', returns)
Ejemplo n.º 17
0
def registration(request):
    logout(request)

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            USER = form.save(commit=True)
            USER.is_active = True
            USER.save()
            from_mail = settings.EMAIL_HOST_USER
            to_list = ['*****@*****.**', settings.EMAIL_HOST_USER]

            current_site = get_current_site(request)
            subject = 'Approve ' + USER.username + ' SACRoom Booking Account'
            message = render_to_string(
                'account_verification_email.html', {
                    'user': USER,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(USER.pk)),
                    'token': account_verification_token.make_token(USER),
                })
            login(request, USER)
            send_mail(subject, message, from_mail, to_list, fail_silently=True)

            return redirect('account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'registration.html', {'form': form})
Ejemplo n.º 18
0
class SignUpFormTest(TestCase):

    def setUp(self):
        self.username = '******'
        self.email = '*****@*****.**'
        self.password = '******'
        self.myForm = SignUpForm({
            'username': self.username,
            'email': self.email,
            'password': self.password})

    def test_SignUpFormIsValid(self):
        self.assertTrue(self.myForm.is_valid())
Ejemplo n.º 19
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.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('index')
    else:
        form = SignUpForm()
    return render(request, 'main/signup.html', {'form': form})
Ejemplo n.º 20
0
def createUser(request):
    jsonResult = {}
    if request.method == 'POST':
        signUpData = SignUpForm(request.POST)
        if signUpData.is_valid():
            user = signUpData.save()
            user.createProfile()
            signUpData.login(request)
            jsonResult["result"] = "OK"
        else:
            jsonResult["result"] = "ERROR"
            jsonResult["errors"] = signUpData.errors
    return JsonResponse(jsonResult)
Ejemplo n.º 21
0
def register_view(request):
    if request.user.is_authenticated(
    ):  # if the user is already logged in then no need to register view
        return HttpResponseRedirect('/')
    else:
        if request.method == 'POST':
            form = SignUpForm(request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/login')
        else:
            form = SignUpForm()
    return render(request, 'register.html', {
        'sc': schools,
        'form': form,
        'error': form.errors
    })
Ejemplo n.º 22
0
def register_user(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            add_perm(user, form.cleaned_data.get('perm'))
            p = Profile.objects.create(user=user)
            Wallet.objects.create(profile=p, balance=0)
            user.profile.save()
            login(request, user)
            return HttpResponseRedirect('/course')
    else:
        form = SignUpForm()
    return render(request, 'register.html', {'form': form})
Ejemplo n.º 23
0
def signup_view(request):
    error_msg = ""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            user = authenticate(username=request.POST['username'],
                                password=request.POST['password1'])
            login(request, user)
            is_registered = Member.objects.filter(
                email=request.POST['email']).exists()
            if is_registered:
                member = Member.objects.get(
                    email__iexact=request.POST['email'])
                if member.name == "Account in Progress":
                    member.name = request.POST['full_name']
                    member.username = request.POST['username']
                    member.owner = False
                    member.save()
                    return redirect('/profile_redirect/')
                else:
                    error_msg = "Email is already registered with our site."
                    return render(request, 'registration/signup.html', {
                        'form': form,
                        'errormsg': error_msg
                    })
            else:
                member = Member(username=request.POST['username'],
                                name=request.POST['full_name'],
                                email=request.POST['email'],
                                owner=False)
                member.save()
            return redirect('/' + member.username + '/joinspace/')
    else:
        if request.user.is_active:
            return redirect('/profile_redirect/')
        else:
            form = SignUpForm()
    return render(request, 'registration/signup.html', {
        'form': form,
        'errormsg': error_msg
    })
Ejemplo n.º 24
0
def signup(request):
    form = SignUpForm(request.POST)
    if form.is_valid():
        user = form.save()
        user.refresh_from_db()
        user.profile.first_name = form.cleaned_data.get('first_name')
        user.profile.last_name = form.cleaned_data.get('last_name')
        user.profile.email = form.cleaned_data.get('email')
        user.save()
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password1')
        user = authenticate(username=username, password=password)
        auth_login(request, user)
        return redirect('profile')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
Ejemplo n.º 25
0
def renderResourceList(request, username, listId):
    returns = {}
    if request.user.is_authenticated is False:
        returns['SignUpForm'] = SignUpForm()
    resourceList = get_object_or_404(ResourceList, id=listId)
    if not resourceList.isPublic:
        if resourceList.creator != request.user:
            return renderIndex(request)
    returns["resourceList"] = resourceList

    resources = Resource.objects.filter(
        resourceList=resourceList).order_by('position')
    returns["jsonResourceList"] = serialize('json', [resourceList],
                                            use_natural_foreign_keys=True)
    returns["jsonResources"] = serialize('json',
                                         resources,
                                         use_natural_foreign_keys=True)

    # Get user's rating and check if list is bookmarked
    ratings = []
    avgRating = 0
    isBookmarked = False

    if request.user.is_authenticated:
        ratings = Rating.objects.filter(user=request.user,
                                        resourceList=resourceList)
        isBookmarked = True if BookmarkedList.objects.filter(
            resourceList=resourceList, user=request.user).exists() else False
        avgRating = resourceList.getUserAvgRating(user=request.user)

    returns["jsonRatings"] = serialize('json',
                                       ratings,
                                       use_natural_foreign_keys=True)
    returns["avgRating"] = avgRating
    returns["isBookmarked"] = isBookmarked
    return render(request, 'user/resourceList.html', returns)
Ejemplo n.º 26
0
def signup(request):
    if request.user.is_authenticated == True:
        return redirect('home')

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.username = form.cleaned_data.get('email')
            obj.save()

            username = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('viewgoals')
    else:
        form = SignUpForm()
    return render(request, 'register.html', {'form': form})
Ejemplo n.º 27
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = SignUpForm(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)
            raise UserFormException()
    else:
        user_form = SignUpForm()

    return render(request, 'main/registration.html', {
        'user_form': user_form,
        'registered': registered
    })
Ejemplo n.º 28
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = True;
            user.save()

            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            message = render_to_string('account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
                'token': account_activation_token.make_token(user),
            })
            user.email_user(subject, message)

            return redirect('account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
Ejemplo n.º 29
0
 def get(self, request):
     form = SignUpForm()
     return render(request, 'signup.html', {'form': form})
Ejemplo n.º 30
0
def login_signup(request):
    login_form = LoginForm(request.POST or None)
    signup_form = SignUpForm(request.POST or None)
    if "Login" in request.POST:
        logout(request)
        print('Login form submitted')
        if login_form.is_valid():
            print('valid login form')
            email = login_form.cleaned_data['email']
            password = login_form.cleaned_data['password']
            try:
                user = authenticate(username=email, password=password)
                auth.login(request, user)
                messages.add_message(request, messages.SUCCESS,
                                     "Login successful")
                return HttpResponseRedirect('/demo')
                # return render(request, 'signup_login.html', {'login_form': login_form, 'signup_form': signup_form})
            except:
                messages.add_message(request, messages.WARNING,
                                     "Username or password wrong")
                return render(request, 'signup_login.html', {
                    'login_form': login_form,
                    'signup_form': signup_form
                })
        else:
            print('INVALID login form')
            messages.add_message(request, messages.WARNING, "Login Failed")
            return render(request, 'signup_login.html', {
                'login_form': login_form,
                'signup_form': signup_form
            })
    if "Signup" in request.POST:
        logout(request)
        print('Signup form submitted')
        if signup_form.is_valid():
            email = signup_form.cleaned_data['email']
            password = signup_form.cleaned_data['password_s']

            if User.objects.filter(email=email).exists():
                messages.add_message(request, messages.WARNING,
                                     "Email Already Exist")
                return render(request, 'signup_login.html', {
                    'login_form': login_form,
                    'signup_form': signup_form
                })
            else:
                user = User.objects.create(username=email)
                user.email = email
                user.set_password(password)
                user.is_staff = False
                user.is_active = True
                user.is_superuser = False
                user.save()
                HypoUser(user=user).save()
                user = authenticate(username=email, password=password)
                auth.login(request, user)
                print('valid signup form')
                messages.add_message(request, messages.SUCCESS,
                                     "Signup Successfull")
                return HttpResponseRedirect('/demo')
                # return render(request, 'signup_login.html', {'login_form': login_form, 'signup_form': signup_form})
        else:
            print('INVALID signup form')
            messages.add_message(request, messages.WARNING,
                                 "Enter a valid email address")
            return render(request, 'signup_login.html', {
                'login_form': login_form,
                'signup_form': signup_form
            })
    else:
        print('handle get')
        return render(request, 'signup_login.html', {
            'login_form': login_form,
            'signup_form': signup_form
        })
Ejemplo n.º 31
0
 def get(self, request):
     form = SignUpForm()
     return render(request, 'main/sign_up.html', context={'form': form, 'user': request.user})