Exemple #1
0
def signup_core(post):
    user_f = UserForm(post)
    profile_f = UserProfileForm(post)
    raw_email = post.get('email', '')

    if validate_email(raw_email) and user_f.is_valid() and profile_f.is_valid():
        email = user_f.cleaned_data['email']
        password = user_f.cleaned_data['password']
        first_name = user_f.cleaned_data['first_name']
        last_name = user_f.cleaned_data['last_name']
        while True:
            username = os.urandom(10).encode('hex')
            if not User.objects.filter(username=username).count():
                break

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

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

        give_email_auth_token(user)

        return user
    else:
        return None
Exemple #2
0
def signup_core(post):
    user_f = UserForm(post)
    profile_f = UserProfileForm(post)
    raw_email = post.get('email', '')

    if validate_email(
            raw_email) and user_f.is_valid() and profile_f.is_valid():
        email = user_f.cleaned_data['email']
        password = user_f.cleaned_data['password']
        first_name = user_f.cleaned_data['first_name']
        last_name = user_f.cleaned_data['last_name']
        while True:
            username = os.urandom(10).encode('hex')
            if not User.objects.filter(username=username).count():
                break

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

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

        give_email_auth_token(user)

        return user
    else:
        return None
Exemple #3
0
def main(request):
    user = request.user
    profile = user.profile

    success = False
    result_con = request.session.pop('result_con', -1)
    if request.method == 'POST':
        user_f = UserForm(request.POST)
        profile_f = UserProfileForm(request.POST, instance=profile)

        if user_f.is_valid() and profile_f.is_valid():
            user.first_name = user_f.cleaned_data['first_name']
            user.last_name = user_f.cleaned_data['last_name']
            user.save()

            profile = profile_f.save()
            success = True
            logger.info('modify', {'r': request})

    return render(
        request, 'account/profile.html', {
            'user': user,
            'profile': profile,
            'success': success,
            'result_con': result_con
        })
Exemple #4
0
def main(request):
    user = request.user
    profile = user.profile

    result_prof = request.session.pop('result_prof', -1)
    result_con = request.session.pop('result_con', -1)
    if request.method == 'POST':
        user_f = UserForm(request.POST)
        profile_f = UserProfileForm(request.POST, instance=profile)

        if user_f.is_valid() and profile_f.is_valid():
            email = user_f.cleaned_data['email']
            if user.email != email:
                user.email = email
                user.profile.email_authed = False
                tokens = EmailAuthToken.objects.filter(user=user).all()
                for token in tokens:
                    token.delete()

            user.first_name = user_f.cleaned_data['first_name']
            user.last_name = user_f.cleaned_data['last_name']
            user.save()

            profile = profile_f.save()
            result_prof = 1
            logger.info('modify', {'r': request})

    context = {
        'user': user,
        'profile': profile,
        'result_prof': result_prof,
        'result_con': result_con,
        'kaist_enabled': settings.KAIST_APP_ENABLED,
    }
    return render(request, 'account/profile.html', context)
Exemple #5
0
def main(request):
    user = request.user
    profile = user.profile

    result_prof = request.session.pop('result_prof', -1)
    result_con = request.session.pop('result_con', -1)
    if request.method == 'POST':
        user_f = UserForm(request.POST)
        profile_f = UserProfileForm(request.POST, instance=profile)

        if user_f.is_valid() and profile_f.is_valid():
            email = user_f.cleaned_data['email']
            if user.email != email:
                user.email = email
                user.profile.email_authed = False

            user.first_name = user_f.cleaned_data['first_name']
            user.last_name = user_f.cleaned_data['last_name']
            user.save()

            profile = profile_f.save()
            result_prof = 1
            logger.info('modify', {'r': request})

    return render(request, 'account/profile.html',
                  {'user': user, 'profile': profile,
                   'result_prof': result_prof, 'result_con': result_con})
Exemple #6
0
def main(request):
    user = request.user
    profile = user.profile

    result_prof = request.session.pop('result_prof', -1)
    result_con = request.session.pop('result_con', -1)
    if request.method == 'POST':
        user_f = UserForm(request.POST)
        profile_f = UserProfileForm(request.POST, instance=profile)

        if user_f.is_valid() and profile_f.is_valid():
            user.first_name = user_f.cleaned_data['first_name']
            user.last_name = user_f.cleaned_data['last_name']
            user.save()

            profile = profile_f.save()
            result_prof = 1

            if profile.birthday:
                birthday_str = profile.birthday.isoformat()
            else:
                birthday_str = ''
            logger.info(
                'update', {
                    'r':
                    request,
                    'extra': [
                        ('name', f'{user.first_name} {user.last_name}'),
                        ('gender', profile.gender),
                        ('birthday', birthday_str),
                    ],
                })

    return render(
        request, 'account/profile.html', {
            'user': user,
            'profile': profile,
            'result_prof': result_prof,
            'result_con': result_con,
            'kaist_enabled': settings.KAIST_APP_ENABLED,
        })
Exemple #7
0
def editar_perfil(request):
	
	profile = request.user.get_profile()

	if request.method == "POST":
		form = UserProfileForm(request.POST, request.FILES, instance = profile)
		if form.is_valid():
			form.save()

			#mas info sobre reverse:
			#https://docs.djangoproject.com/en/dev/topics/http/urls/
			return HttpResponseRedirect( reverse('home') )
		
	else:
		form = UserProfileForm( instance = profile )

	values = {
		'title':'Editando tu perfil',
		'form':form,
	}
	return render_to_response("core/editar_perfil.html", values, context_instance=RequestContext(request))	
Exemple #8
0
def main(request):
    user = request.user
    profile = user.profile

    success = False
    result_con = request.session.pop('result_con', -1)
    if request.method == 'POST':
        user_f = UserForm(request.POST)
        profile_f = UserProfileForm(request.POST, instance=profile)

        if user_f.is_valid() and profile_f.is_valid():
            user.first_name = user_f.cleaned_data['first_name']
            user.last_name = user_f.cleaned_data['last_name']
            user.save()

            profile = profile_f.save()
            success = True
            logger.info('modify', {'r': request})

    return render(request, 'account/profile.html',
                  {'user': user, 'profile': profile,
                   'success': success, 'result_con': result_con})