def micuenta_datos(request): log.info('VIEW: profile') row = request.user # pedidos = Pedido.objects.filter(usuario_id=str(row.id)) # direcciones = Direccion.objects.filter(usuario=row) paises = Paises.objects.all().order_by('nombre') if request.method == 'POST': print request.POST # print 'post post' form = EditUsuarioForm(request.POST) # print form if form.is_valid(): row = form.update(row.pk) mensajes_auth(request, 'login.cuenta.update') # messages.success(request, 'Se actualizó satisfactoriamente') return redirect('custom_auth:micuenta_datos') else: messages.error(request, 'Formulario no valido') log.warning('Error de formulario') else: initial = model_to_dict(row) form = EditUsuarioForm(initial) try: return render('web/actualizar-datos.html', locals(), context_instance=ctx(request)) except Exception as e: return render('custom_auth/micuenta-datos.html', locals(), context_instance=ctx(request))
def set_password(request, uuid_hash): log.info('VIEW: set_password') if request.method == 'POST': form = SetPasswordForm(request.POST) if form.is_valid(): form.save() # form.enviaEmail() mensajes_auth(request, 'login.set_password.envio') # messages.success(request, u'Se ha actualizado satisfatoriamente, ahora puede iniciar sesión con la nueva contraseña') return HttpResponseRedirect( reverse('custom_auth:set_password_success')) else: print(form.errors) log.warning('Error de formulario') else: try: user = Usuario.objects.get(uuid_hash=uuid_hash) except Usuario.DoesNotExist(): user = None form = SetPasswordForm(initial={ 'email': user.email, 'uuid_hash': uuid_hash }) return render('custom_auth/password/set-password.html', locals(), context_instance=ctx(request))
def login_view(request): if request.user.is_authenticated(): return redirect('custom_auth:micuenta_datos') # row, created = InfoAcceso.objects.get_or_create(pk=1) error_accesos = True if request.method == 'POST': next_url = request.POST.get('next', '') form = LoginForm(request.POST) if form.is_valid(): user = form.auth() # print ufmisser if user is not None: if user.is_active: user.last_login = datetime.now() user.save() login(request, user) # mensajes_auth(request, 'login.inicio.ok') # messages.success(request, u'Bienvenido, Se ha registrado e iniciado sesión satisfactoriamente') sesioncarrito = request.session.get('sesioncarrito', '') next_url = request.POST.get('next', '') if next_url: return redirect(next_url) if sesioncarrito: return redirect('pedidos:carrito') return redirect('custom_auth:micuenta_datos') # return redirect('web:home') else: user_inactive = True else: error_accesos = True mensajes_auth(request, 'login.acceso.error') # return render(request, 'web/acceso/_ingresar-catalogo.html', locals()) else: next_url = request.GET.get('next', '') form = LoginForm() # if error_accesos: # mensajes_auth(request, 'login.acceso.error') # row, created = InfoLogin.objects.get_or_create(pk=1) meta_title = u'Login' # return render(request, 'web/acceso/ingresar-catalogo.html', locals()) try: return render('web/iniciar-sesion.html', locals(), context_instance=ctx(request)) except Exception as e: return render('custom_auth/login.html', locals(), context_instance=ctx(request))
def registro(request): log.info('VIEW: registro') # if request.user.is_authenticated(): # return redirect(reverse('custom_auth:myaccount')) nexturl = request.GET.get('next', '') if request.method == 'POST': form = RegistroForm(request.POST) nexturl = request.POST.get('nexturl', None) # print form if form.is_valid(): form.save() user = form.auth() form.enviaEmail() login(request, user) mensajes_auth(request, 'login.registro.ok') # messages.success(request, u'Bienvenido, Se ha registrado e iniciado sesión satisfactoriamente') sesioncarrito = request.session.get('sesioncarrito', '') if sesioncarrito: return redirect('pedidos:carrito') else: print(form.errors) return redirect('custom_auth:micuenta_datos') else: print(form.errors) return redirect('custom_auth:login') log.warning('Error de formulario') else: form = RegistroForm() try: return render('web/registrate.html', locals(), context_instance=ctx(request)) except Exception as e: return render('custom_auth/registro.html', locals(), context_instance=ctx(request))
def recupera_password(request): log.info('VIEW: recupera_passowrd') if request.method == 'POST': form = RecuperaPasswordForm(request.POST) if form.is_valid(): form.enviaEmail() mensajes_auth(request, 'login.recuera_password.envio') return redirect('custom_auth:login') else: print(form.errors) log.warning('Error de formulario') else: form = RecuperaPasswordForm() try: return render('web/olvidaste-contrasenia.html', locals(), context_instance=ctx(request)) except Exception as e: return render('custom_auth/password/recupera-password.html', locals(), context_instance=ctx(request))