Example #1
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 HttpResponse('hello')
    return render_to_response(
            'login/register.html',
            {'user_form': user_form, 'registered': registered},
            context)
Example #2
0
def signup_view(request):
    if request.method == "POST":
        user_profile_form = UserProfileForm(request.POST,request.FILES)
        user_form  = UserForm(request.POST)
        
         
        if user_form.is_valid() and user_profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            user_profile = user_profile_form.save(commit=False)
            user_profile.user = user;
            if 'profile_image' in request.FILES:
                user_profile.profile_image = request.FILES['profile_image']
            
            user_profile.save()

            return redirect("/login/")
        else:
            return HttpResponse("Form Not Valid !")
    else:
        user_form = UserForm()
        user_profile_form = UserProfileForm()
        context_dict ={"user_form":user_form,"user_profile_form":user_profile_form};
        return render(request,'signup.html',context_dict)
Example #3
0
def signup(request):
	if request.method == 'POST':
		userform = UserForm(request.POST, prefix='user')
		profileform = ProfileForm(request.POST, request.FILES, prefix='profile')
		if userform.is_valid() * profileform.is_valid():
			user = userform.save()
			profile = profileform.save(commit=False)
			profile.user = user
			profile.save()
			return HttpResponse('Signup successful <br> <a href="/login/login">Login Here</a>')
	else:
		userform = UserForm(prefix='user')
		profileform = ProfileForm(prefix='profile')
	return render_to_response('login/sign_up.html',dict(userform=userform,profileform=profileform),context_instance=RequestContext(request))
Example #4
0
def signin(request):
    if request.GET:
        formUser = UserForm(request.GET)
        formUtilisateur = UtilisateurForm(request.GET)
        if formUser.is_valid() and formUtilisateur.is_valid():
            user=formUser.save()
            user.set_password(formUser.cleaned_data["password"])
            user.save()
            utilisateur = Utilisateur(profilBase=user, birthday=formUtilisateur.cleaned_data["birthday"])
            utilisateur.save()
            return(HttpResponseRedirect('/login'))
        else:
            return(render_to_response("signin.html",{"formUser":formUser, "formUtilisateur":formUtilisateur}))
    else:
        formUser = UserForm()
        formUtilisateur = UtilisateurForm()
        context = RequestContext(request,{"formUser":formUser, "formUtilisateur":formUtilisateur})
        return(render_to_response("signin.html",context))
Example #5
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)
        
        # If the two forms are valid...
        if user_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()

            # 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

    # 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()

    # Render the template depending on the context.
    return render_to_response(
            'login/register.html',
            {'user_form': user_form, 'registered': registered},
            context)
Example #6
0
def signup_view(request):
    dict = {}
    form1 = UserForm()
    form2 = MyUserForm()
    if request.POST:
        form1 = UserForm(request.POST)
        form2 = MyUserForm(request.POST)
        if form1.is_valid() and form2.is_valid():
            data = form1.cleaned_data
            form1.save()
            obj=form2.save(commit=False)
            obj.user=User.objects.get(username = data['username'])
            obj.save()
            form2.save_m2m()
            messages.add_message(request, messages.INFO, " You have successfully registered. You can sign in now.")
            return (redirect(reverse('home')))
    dict['form1'] = form1
    dict['form2'] = form2
    return render_to_response('signup.html',dict,context_instance=RequestContext(request))
Example #7
0
def login_view(request):
    login_incorrecto=""
    formulario_login=AuthenticationForm()
    user_form = UserForm()
    perfil_form=PerfilForm()
    error_en_registro=False
    exito=False
    if request.method=='POST':
        formulario_login=AuthenticationForm(request.POST)
        user_form=UserForm(request.POST)
        perfil_form=PerfilForm(request.POST, request.FILES)
        if 'entrar' in request.POST:
            if formulario_login.is_valid:
                usuario=request.POST['username']
                clave=request.POST['password']
                acceso=authenticate(username=usuario, password=clave)
                if acceso is not None:
                    if acceso.is_active:
                        login(request, acceso)
                        return HttpResponseRedirect('/redsocial')
                    else:
                        return render_to_response('noactivo.html', context_instance=RequestContext(request))
                else:
                    error_login=True
                    login_incorrecto="El nick o password no son validos."
                    formulario_login=AuthenticationForm()
                    user_form = UserForm()
                    perfil_form=PerfilForm()
                    return render_to_response('login.html', {'formulario_login':formulario_login, 'user_form':user_form, 'perfil_form':perfil_form, 'login_incorrecto':login_incorrecto, 'error':error_login} ,context_instance=RequestContext(request) )
        elif 'registrar' in request.POST:
            #AQUI TENEMOS QUE COMPROBAR SI EL FORMULARIO ES VALIDO
            #if messageform.is_valid():   <-- INCLUIR EL PARENTESIS http://stackoverflow.com/questions/5358566/saving-modelform-erroruser-message-could-not-be-created-because-the-data-didnt
            if user_form.is_valid():
                user = user_form.save()
                user.is_active = False
                user.save()
                confirmation_code = ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for x in range(33))
                if perfil_form.is_valid():
                    perfil=perfil_form.save(commit=False) #tenemos que add el usuario
                    perfil.user=user #add el usuario al perfil 
                    perfil.confirmation_code=confirmation_code #ADD confirmation code to perfil
                    perfil.save() #guardamos el perfil
                    send_registration_confirmation(user)
                    print "REDIRECCIONAMOS A INICIO"
                    exito=True
                    #VOLVEMOS A CARGAR LOS FORMULARIOS VACIOS
                    formulario_login=AuthenticationForm()
                    user_form = UserForm()
                    perfil_form=PerfilForm()
                    return render_to_response('login.html', {'formulario_login':formulario_login, 'user_form':user_form, 'perfil_form':perfil_form, 'login_incorrecto':login_incorrecto, 'error':error_en_registro, 'exito':exito}, context_instance=RequestContext(request))
                else:
                    print "EL PERFIL_FORM NO ES VALID"
                    user.delete()
            else:
                print "EL USERFORM NO ES VALID"
        else:
            return HttpResponseRedirect('/quedise')          
    return render_to_response('login.html', {'formulario_login':formulario_login, 'user_form':user_form, 'perfil_form':perfil_form, 'login_incorrecto':login_incorrecto, 'error':error_en_registro, 'exito':exito}, context_instance=RequestContext(request))
Example #8
0
def register(request):
    # Need an user in database to register a new user.
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/')

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

        # If the two forms are valid...
        if user_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()

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

    # 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()

    # Render the template depending on the context.
    return render(request, 
            'register.html',
            {'user_form': user_form, 'registered': registered})
def signup(request):
    dicti = dict()
    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(commit=False)
            try:
                validate_password(user.password)
            except:
                dicti['error'] = "Password Entered Is Too Week To Be Accepted."
                dicti['user_form'] = UserForm()
                dicti['profile_form'] = UserProfileInfoForm()
                return render(request, 'login/signup.html', context=dicti)
            if User.objects.filter(email__iexact=user.email):
                dicti[
                    'error'] = "Please Select A New E-Mail. This E-Mail is already In Use."
                dicti['user_form'] = UserForm()
                dicti['profile_form'] = UserProfileInfoForm()
                return render(request, 'login/signup.html', context=dicti)
            else:
                user.set_password(user.password)
                user.save()
                profile = profile_form.save(commit=False)
                profile.user = user
                profile.save()
                return HttpResponseRedirect(reverse('login:signin'))
        else:
            dicti[
                'error'] = "Please Select A New User Name. This User Name is already In Use."
            dicti['user_form'] = UserForm()
            dicti['profile_form'] = UserProfileInfoForm()
    else:
        dicti['user_form'] = UserForm()
        dicti['profile_form'] = UserProfileInfoForm()

    return render(request, 'login/signup.html', context=dicti)
Example #10
0
def sign_up(request):
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        if user_form.is_valid():
              user = user_form.save()
              user.set_password(user.password)
              user.save()
              return redirect('/login')
    elif request.method == 'GET':
        user_form = UserForm()
    else:
        return HttpResponseBadRequest
    template = loader.get_template('login/sign_up.html')
    context = {
            'user_form': user_form,
    }
    return HttpResponse(template.render(context, request))
Example #11
0
def print(request, nid):
    uf = UserForm()
    rfv = report.objects.get(pk=nid)
    if request.method == 'GET':
        if request.session['user_name'] == rfv.repdoctor:
            rf = ReportForm(
                initial={
                    'name': rfv.name,
                    'examnum': rfv.examnum,
                    'sex': rfv.sex,
                    'age': rfv.age,
                    'ageunit': rfv.ageunit,
                    'position': rfv.position,
                    'examtype': rfv.examtype,
                    'method': rfv.method,
                    'hospital': rfv.hospital,
                    'indication': rfv.indication,
                    'findings': rfv.findings,
                    'comments': rfv.comments,
                    'examdate': rfv.examdate,
                    'repdoctor': rfv.repdoctor,
                    'reportdate': rfv.reportdate,
                    'status': rfv.status
                })
            if rfv.hospital == "2":
                return render(request, 'login/CDHrep.htm', {
                    'nid': nid,
                    'rf': rf,
                    'uf': uf
                })
            elif rfv.hospital == "1":
                return render(request, 'login/UTHrep.htm', {
                    'nid': nid,
                    'rf': rf,
                    'uf': uf
                })
    else:
        return redirect("/creat/")
Example #12
0
def register(request):
    success = False
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.set_password(user.password)
            user.communityRating = 1500
            user.appJoinDate = datetime.date.today()
            user.save()
            login(request, user)
            success = True
    else:
        form = UserForm()
    return render(request, 'login/register.html', {
        'form': form,
        'success': success
    })
Example #13
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, 'login/register.html', {
        'user_form': user_form,
        'registered': registered
    })
Example #14
0
def register(request):
    error = ""
    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():
            if  validate(user_form.cleaned_data.get("email")):
                
                otp_no = random.randint(1000000, 9999999)
                mail = EmailMessage('Sports Room Authentication', 'Authentication key: '+str(otp_no), 
                    to=[user_form.cleaned_data.get("email")])
                mail.send()

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

                profile = profile_form.save(commit=False)
                profile.user = user
                profile.otp_no = otp_no
                if 'profile_pic' in request.FILES:
                    profile.profile_pic = request.FILES['profile_pic']

                profile.save()

                registered = True
                return render(request,'Login/otp.html',{'otp_no':otp_no,
                    'email':user_form.cleaned_data.get("email")})
            else:
                error = "IIITB email required"
        else:
            print(user_form.errors,profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(request,'Login/register.html',{
            'user_form':user_form,
            'profile_form':profile_form,
            'registered':registered,
            'error' : error
    })
Example #15
0
File: views.py Project: helgurd/DMS
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():
            # 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()
            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
    # 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('login/register.html', {
        'user_form': user_form,
        'registered': registered
    }, context)
Example #16
0
def login(request):
    if request.method == "POST":
        login_form = UserForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            if len(username) < 8:
                message = "ユーザ名は8桁で入力してください。"
            elif not isalnum(username):
                message = "ユーザ名は半角英数字で入力してください。"
            else:
                try:
                    user = models.User.objects.get(USERID=username)
                    if user.PASSWORD == password:
                        return render(request, 'index.html')
                    else:
                        message = "ユーザ名またはパスワードに誤りがあります。"
                except Exception:
                    message = "ユーザ名またはパスワードに誤りがあります。"
            login_form = UserForm(initial={'username': username,
                                           'password': password})
        return render(request, 'login.html', locals())
    login_form = UserForm()
    return render(request, 'login.html', locals())
Example #17
0
def register(request):
    # Need an user in database to register a new user.
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/')

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

        # If the two forms are valid...
        if user_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()

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

    # 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()

    # Render the template depending on the context.
    return render(request, 'register.html', {
        'user_form': user_form,
        'registered': registered
    })
Example #18
0
def register(request):

    registered = False

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

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

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

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

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

            profile.save()

            registered = True

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

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

    return render(
        request, 'login/regristration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Example #19
0
def register(request):
    error = ""
    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():
            if validate(user_form.cleaned_data.get("email")):
                user = user_form.save()
                user.set_password(user.password)
                user.save()

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

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

                profile.save()

                registered = True
            else:
                error = "IIITB email required"
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'Login/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
            'error': error
        })
Example #20
0
 def test_form4(self):
     form_data = {'username': '******',
                  'email': 'gouthu123',
                  'password': '******'}
     form = UserForm(data=form_data)
     self.assertFalse(form.is_valid())
Example #21
0
 def test_form3(self):
     form_data = {'username': '******',
                  'email': '*****@*****.**',
                  'password': '******'}
     form = UserForm(data=form_data)
     self.assertTrue(form.is_valid())