def login_view(request): if request.user.is_authenticated: return HttpResponseRedirect('/idle_app/landing/') if request.method == 'GET': form = AuthenticationForm() return render(request, '_login.html', {'form': form}) if request.method == 'POST': form = AuthenticationForm(request=request, data=request.POST) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') user = authenticate(username=username, password=password) if user is not None: print(user, request) login(request, user) return HttpResponseRedirect('/idle_app/landing/') else: print('User not found') return render(request, '_login.html', {'form': form}) else: # If there were errors, we render the form with these # errors return render(request, '_login.html', {'form': form})
def loguet_in(request): if not request.user.is_anonymous(): return HttpResponseRedirect('/private') if request.method == 'POST': formulario = AuthenticationForm(request.POST) if formulario.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) if 'next' in request.GET: return HttpResponseRedirect(str(request.GET['next'])) else: if acceso.is_superuser: return HttpResponseRedirect('/administrador') else: return HttpResponseRedirect('/private') else: return render_to_response('user/noactivo.html', context_instance=RequestContext(request)) else: return render_to_response('user/nousuario.html', context_instance=RequestContext(request)) else: formulario = AuthenticationForm() return render_to_response('user/user_login.html',{'formulario':formulario}, context_instance=RequestContext(request))
def password_nuevo(request): algo="" if request.method == 'POST' : formulario2=newpass(request.POST) if formulario2.is_valid(): contrasena=request.POST['actual_password'] usuario=request.user acceso=authenticate(username=usuario,password=contrasena) if acceso is not None: formulario = AdminPasswordChangeForm(user=usuario, data=request.POST) if formulario.is_valid(): formulario.save() logout(request) return HttpResponseRedirect("/db/menu/loginlink/") pass else: formulario = AdminPasswordChangeForm(user=request.user) formulario2 = newpass() algo="Las contrasena actual no es la misma" return render_to_response('repassword.html', {'formulario' :formulario, "formulario2": formulario2, "algo": algo}, context_instance=RequestContext(request)) pass else: formulario = AdminPasswordChangeForm(user=request.user) formulario2 = newpass() return render_to_response('repassword.html', {'formulario' :formulario, "formulario2": formulario2}, context_instance=RequestContext(request))
def ingresar(request): if request.user.is_authenticated(): return HttpResponseRedirect('/dashboard/') if request.method == 'POST': formulario = AuthenticationForm(request.POST) if formulario.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: empleado = Empleado.objects.filter(user__username=usuario) for x in empleado.values('foto'): for i in x: request.session['foto'] = x[i] for x in empleado.values('nombre'): for i in x: request.session['nombre'] = x[i] for x in empleado.values('apellido'): for i in x: request.session['apellido'] = x[i] for x in empleado.values('id'): for i in x: request.session['id'] = x[i] login(request, acceso) return HttpResponseRedirect('/dashboard') else: return render_to_response('noactivo.html', context_instance=RequestContext(request)) else: return render_to_response('nousuario.html', context_instance=RequestContext(request)) else: formulario = AuthenticationForm() return render_to_response('index.html', {'formulario': formulario}, context_instance=RequestContext(request))
def clean(self): username = self.cleaned_data.get("username") password = self.cleaned_data.get("password") try: if username is not None and password: self.user_cache = authenticate(self.request, username=username, password=password) if self.user_cache is None: try: user_temp = User.objects.get(email=username) except: user_temp = None if user_temp is not None: self.confirm_login_allowed(user_temp) else: raise forms.ValidationError( self.error_messages["invalid_login"], code="invalid_login", params={ "username": self.username_field.verbose_name }, ) except Exception as e: print(e) raise e return self.cleaned_data
def clean(self): if self.is_valid(): email = self.cleaned_data['email'] password = self.cleaned_data['password'] if not authenticate(email=email, password=password): raise forms.ValidationError( "Invalid login or password. Try again")
def loguet_in(request): if not request.user.is_anonymous(): return HttpResponseRedirect('/private') if request.method == 'POST': formulario = AuthenticationForm(request.POST) if formulario.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) if 'next' in request.GET: return HttpResponseRedirect(str(request.GET['next'])) else: if acceso.is_superuser: return HttpResponseRedirect('/administrador') else: return HttpResponseRedirect('/private') else: return render_to_response( 'user/noactivo.html', context_instance=RequestContext(request)) else: return render_to_response( 'user/nousuario.html', context_instance=RequestContext(request)) else: formulario = AuthenticationForm() return render_to_response('user/user_login.html', {'formulario': formulario}, context_instance=RequestContext(request))
def clean(self): email = self.cleaned_data.get('email') password = self.cleaned_data.get('password') user = authenticate(username=email, password=password) if not user or not user.is_active: raise forms.ValidationError("Sorry, that login was invalid. Please try again.") return self.cleaned_data
def clean(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') user = authenticate(username=username, password=password) if not user or not user.is_active: raise forms.ValidationError('No se encuentran datos que coincidan') return self.cleaned_data
def clean(self, *args, **kwargs): username = self.cleaned_data.get("username") password = self.cleaned_data.get("password") if username and password: user = authenticate(username=username, password=password) if not user: raise forms.ValidationError("Wrong username or password")
def ajax_login(request): if request.method == "POST": user = authenticate(username=request.POST["username"], password=request.POST["password"]) if user is not None and user.is_active: login(request, user) return HttpResponse(json.dumps({"msg": u"Logado", "status": True})) return HttpResponse(json.dumps({"msg": u"Usuário inválido", "status": False}))
def loginuser(request): if request.method == 'GET': return render(request, 'todo/loginform.html', {'form': AuthenticationForm()}) else: user = authenticate(request, username=request.POST['username'], password=request.POST['password']) if user is None: return render(request, 'todo/loginform.html', {'form': AuthenticationForm(), 'errMsg': 'user does not exits'}) else: login(request, user) return redirect('mytodos')
def inicio(request): if request.method == 'POST': authenticate_form = AuthenticationForm(data=request.POST) if authenticate_form.is_valid(): a = authenticate(username=request.POST.get('username'), password=request.POST.get('password')) if a is not None: if a.is_active: login(request, a) nombre = Empleado.objects.filter(usuario=request.user).values('nombre') if len(nombre) == 0: nombre = Mozo.objects.filter(usuario=request.user).values('nombre') if len(nombre) != 0: for i in nombre: for x in i: request.session['nombre'] = i[x] apellido = Empleado.objects.filter(usuario=request.user).values('apellido') if len(apellido) == 0: apellido = Mozo.objects.filter(usuario=request.user).values('apellido') for i in apellido: for x in i: request.session['apellido'] = i[x] usuario = User.objects.filter(username=request.user.username).values('id') print('**********usuario aca ****************') print(usuario) for i in usuario: for x in i: request.session['id_usuario'] = i[x] foto = Empleado.objects.filter(usuario=request.user).values('foto') if len(foto) == 0: foto = Mozo.objects.filter(usuario=request.user).values('foto') for i in foto: for x in i: request.session['foto'] = i[x] sexo = Empleado.objects.filter(usuario=request.user).values('sexo') if len(sexo) == 0: sexo = Mozo.objects.filter(usuario=request.user).values('sexo') for i in sexo: for x in i: request.session['sexo'] = i[x] return HttpResponseRedirect('/inicio/') else: return render_to_response('seguridad/login.html', {'form': authenticate_form}, context_instance=RequestContext(request)) else: return render_to_response('seguridad/login.html', {'form': authenticate_form}, context_instance=RequestContext(request)) else: if not request.user.is_authenticated(): authenticate_form = AuthenticationForm() return render_to_response('seguridad/login.html', {'form': authenticate_form}, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/inicio/')
def signup_view(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('courses:list') else: form = SignUpForm() return render(request, 'accounts/signup.html', {'form': form})
def logins(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') user = authenticate(request, username=username, password=password) if user is not None: login(request, user) return redirect('/dashboard/') else: return redirect('/') else: return redirect('/')
def clean(self, *args, **kwargs): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') if username and password: user = authenticate(username=username, password=password) if not user: raise forms.ValidationError('User does not exists') if not user.check_password(password): raise forms.ValidationError('Incorrect Password') if not user.is_active: raise forms.ValidationError('This user is not active') return super(loginform, self).clean(*args, **kwargs)
def clean(self, *args, **kwargs): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') if username and password: user = authenticate(username=username, password=password) if not user: raise forms.ValidationError("this user does not exist") if not user.check_password(password): raise forms.ValidationError('the passport does not match') if not user.is_active: raise forms.ValidationError('user is not active') return super(UserLoginForm, self).clean(*args, **kwargs)
def clean(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') if username is not None and password: self.user_cache = authenticate(self.request, username=username, password=password) if self.user_cache is None: pass else: self.confirm_login_allowed(self.user_cache) return self.cleaned_data
def login_process(request): if request.method == "POST": username = request.POST.get("username") password = request.POST.get("password") user = authenticate( username=username, password=password) #if none then the data stored is none if user: login(request, user) return render(request, 'home.html') else: return render(request, 'login.html', {"error": True}) return render(request, 'login.html')
def signup(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() new_user = authenticate( username=form.cleaned_data['username'], password=form.cleaned_data['password1'], ) login(request, new_user) return HttpResponseRedirect('/idle_app/landing/') else: form = RegistrationForm() return render(request, 'sign_up.html', {'form': form})
def log(request): if request.method == 'GET': return render(request, "log.html") elif request.method == 'POST': username = request.POST['logname'] password = request.POST['logpass'] user = authenticate(username=username, password=password) if user is not None: login(request, user) request.session['username'] = username return HttpResponseRedirect("/questionlist/") else: messages.error(request, '用户名不存在或者密码错误') return render(request, "log.html")
def register(request): if request.method == 'POST': form = MyUserCreationForm(request.POST) if form.is_valid(): #new_user = form.save() username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = authenticate(username=username, password=password) login(request, user) return HttpResponseRedirect("/admin") else: form = MyUserCreationForm() return render(request, 'register.html', { 'form': form, })
def login(req): form = userLogin() if req.method == 'POST': form = userLogin(req.POST) if form.is_valid(): user = forms.authenticate(username=req.POST['username'], password=req.POST['password']) print('rakesh', user) if user is None: messages.info(req, 'username or password is not Validate') return redirect('/accounts/login') else: authenticate(req, user) return redirect('/blog/home') return render(req, 'login.html', {'form': form})
def login(request): if request.method == "POST": form = AuthenticationForm(request, data=request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(username=username, password=password) return redirect('home') #return redirect(reverse('home')) else: messages.info(request, 'Invalid Credentials') return redirect(reverse('Login')) Login_form = AuthenticationForm() return render(request, 'authentication/Login.html', {"Login_form": Login_form})
def usr_reg_app(request): if request.method == 'POST': form_ucf = UserCreationForm(request.POST) if form_ucf.is_valid(): username = form_ucf.cleaned_data.get('username') password = form_ucf.cleaned_data.get('password') gusr = authenticate(username=username, password=password) login(request, gusr) return redirect('/') else: form_ucf = UserCreationForm() context = { 'form_ucf': form_ucf, } return render(request, 'usr_account/usr_register.html', context)
def Login_View(request): if request.method == 'POST': fm = AuthenticationForm(request=request, data=request.POST) if fm.is_valid(): uname = fm.cleaned_data['username'] upass = fm.cleaned_data['password'] user = authenticate(username=uname, password=upass) if user is not None: login(request, user) return redirect('student_add') else: fm = AuthenticationForm() template_name = 'student/login.html' context = {'form': fm} return render(request, template_name, context)
def login_page(request) -> render or redirect: form = AuthenticationForm() if request.method == "POST": username = request.POST.get('username') password = request.POST.get('password') user = authenticate(request, username=username, password=password) if user is not None: login(request, user) return redirect('/') else: print('form is not valid') else: print('request is not POST') context = {'form': form} return render(request, 'university/authentication/login.html', context)
def loginuser(request): if request.method == 'GET': return render(request, 'todo/loginuser.html', {'form': AuthenticationForm()}) else: user = authenticate(request, username=request.POST['username'], password=request.POST['password']) if user is None: return render(request, 'todo/loginuser.html', { 'form': AuthenticationForm(), 'error': 'User doesnt match' }) else: login(request, user) return redirect("currenttodos")
def login_fun(request): if request.method == "POST": form = AuthenticationForm(request=request, data=request.POST) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') user = authenticate(username=username, password=password) if user is not None: login(request, user) return redirect('home') else: messages.error(request, "invalid") else: messages.error(request, "invalid") form = AuthenticationForm() return render(request=request, template_name="login.html", context={"form": form})
def my_login(request): if request.method == 'POST': login_form = AuthenticationForm(request) username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request,user) return HttpResponseRedirect('/organizations') else: login_errors = '用户未激活' else: login_errors = '用户名或密码不正确' else: login_form = AuthenticationForm return render(request,'login.html',locals())
def clean(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') if username is not None and password: self.user_cache = authenticate(self.request, username=username, password=password) if self.user_cache is None: raise forms.ValidationError( self.error_messages['invalid_login'], code='invalid_login', params={'username': self.username_field.verbose_name}, ) else: self.confirm_login_allowed(self.user_cache) return self.cleaned_data
def login(request): form = AuthenticationForm if request.method == "POST": form = AuthenticationForm(data=request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(username=username, password=password) if user is not None: do_login(request, user) if user.is_superuser: return redirect('logs/') if user.boolean == True: return redirect('home/') else: return redirect('modificar_cuenta/') return render(request, 'registros/index_login.html', {'form': form})
def my_login(request): if request.method == 'POST': login_form = AuthenticationForm(request) username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect('/organizations') else: login_errors = '用户未激活' else: login_errors = '用户名或密码不正确' else: login_form = AuthenticationForm return render(request, 'login.html', locals())
def signup(request): if request.method == 'POST': form = UserSignUp(request.POST) if form.is_valid(): user = form.save() user.refresh_from_db() user.profile.date_of_birth = form.cleaned_data.get('date_of_birth') user.profile.city = form.cleaned_data.get('city') user.profile.gender = form.cleaned_data.get('gender') user.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) logger.info(str(username) + " Creates new accounts on Toob") login(request, user) return redirect('/') else: form = UserSignUp() return render(request, 'signup.html', {'form': form})
def login_request(request): if request.method == 'POST': form = AuthenticationForm(request=request, data=request.POST) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') user = authenticate(username=username, password=password) if user is not None: login(request, user) messages.info(request, f"You are now logged in as {username}") return redirect('/') else: messages.error(request, "Invalid username or password.") else: messages.error(request, "Invalid username or password.") form = AuthenticationForm() return render(request=request, template_name="registration/login.html", context={"form": form})
def ajax_signup(request): errors = [] if not request.is_ajax(): return HttpResponse(":)") if request.method == "POST": form = RegisterForm(request.POST) if form.is_valid(): user = form.save() password = form.cleaned_data.get("password") # autentica usuario e redireciona via js new_user = authenticate(username=user.email, password=password) if new_user: print login(request, new_user) return HttpResponse(json.dumps({"status": True, "errors": []}), mimetype="application/json") else: msg = "Erro no cadastro" errors = form.errors return HttpResponse(json.dumps({"status": False, "msg": msg, "errors": errors}), mimetype="application/json") return HttpResponse(":)")
def user_login(request): if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): cd = form.cleaned_data user = authenticate(request, username=cd['username'], password=cd['password']) if user is not None: if user.is_active: login(request, user) return redirect('post:post_list_view') else: return HttpResponse("Account is Disabled") else: messages.warning(request, "Invalid Username and Password") else: form = LoginForm() return render(request, 'registration/login.html', {'form': form})
def Login(request): if not request.user.is_anonymous(): return HttpResponseRedirect('/db/menu/') if request.method == 'POST': formulario = AuthenticationForm(request.POST) if formulario.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('/db/menu/') else: return HttpResponseRedirect('/db/menu/') else: return HttpResponseRedirect('/db/menu/') else: formulario = AuthenticationForm() return render_to_response("login.html",{'formulario':formulario}, context_instance=RequestContext(request))
def index(request): if not request.user.is_anonymous(): return HttpResponseRedirect('/privado') if request.method == 'POST': formulario = AuthenticationForm(request.POST) if formulario.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 render_to_response('base.html',{'entrada_b':blog_p(request),'dato':filtro(request), 'cate':categorias(request)},context_instance=RequestContext(request)) else: return render_to_response ('user/noactivo.html',context_instance = RequestContext(request)) else: return render_to_response ('user/nousuario.html',context_instance = RequestContext(request)) else: formulario = AuthenticationForm() return render_to_response('base.html',{'logeo':formulario, 'entrada_b':blog_p(request), 'cate':categorias(request)},context_instance=RequestContext(request))
def iniciar_sesion(request): """ Vista de inicio de sesion * Si el usuario inicia sesion con exito, retorna iniciar_sesion.html * Si el usuario esta inactivo, retorna no_activo.html * Si el usuario no exite en el sistema, retorna sesion_error.html * Variables - formulario: es el formulario que el usuario debe completar para iniciar sesion - usuario_actor: es el usuario que realiza la accion - clave: es la clave secreta introducida por el usuario_actor - acceso: contiene el resultado de la funcion authenticate que lleva como parametro el par(usuario, contrasenha) verificando su existencia y estado en el sistema @type request: django.http.HttpRequest @param request: Contiene informacion sobre la solicitud web actual que llamo a esta vista @rtype: django.http.HttpResponseRedirect @rtype: django.shortcuts.render_to_response @return: Se retorna al inicio o se manda a la pagina de login @author: Isaac Veron """ if not request.user.is_anonymous(): return HttpResponseRedirect('/index/') if request.method == 'POST': formulario = AuthenticationForm(request.POST) if formulario.is_valid: usuario_actor = request.POST['username'] clave = request.POST['password'] acceso = authenticate(username=usuario_actor, password=clave) if acceso is not None: if acceso.is_active: login(request, acceso) return HttpResponseRedirect('/index/') else: return render_to_response('no_activo.html', context_instance=RequestContext(request)) else: return render_to_response('autenticacion/sesion_error.html', context_instance=RequestContext(request)) else: formulario = AuthenticationForm() return render_to_response('autenticacion/login.html', {'formulario': formulario}, context_instance=RequestContext(request))