Exemple #1
0
def login():
    if 'username' in session:
        return redirect(url_for("main.home"))

    form = LoginForm()

    if request.method == "POST":
        if form.validate() == False:
            return render_template("main/login.html", form=form)
        else:
            user = form.username.data
            password = form.password.data

            db_user = User2.query.filter_by(username=user).first()
            if db_user is not None and db_user.check_password(
                    password) and db_user.chall == session['chall']:
                session['username'] = user
                session['admin'] = db_user.isAdmin
                return redirect(url_for("main.home"))
            else:
                msg = "Username/Password Incorrect"
                return render_template("main/login.html", msg=msg, form=form)

    elif request.method == "GET":
        session['chall'] = request.args.get("chall")
        return render_template("main/login.html", form=form)
Exemple #2
0
def login():

    if current_user.is_authenticated:
        flash("Already Logged In.", "success")
        return redirect(url_for("home"))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get("next")
            flash(f"Login Successful. Welcome {user.username}", "success")

            # Stored until user has logged out
            session["username"] = user.username
            session["email"] = user.email

            if form.category.data == "Employer":
                return (redirect(next_page) if next_page else redirect(
                    url_for("employer")))
            elif form.category.data == "Employee":
                return (
                    # redirect(next_page) if next_page else redirect(url_for("employee"))
                    plaid_authenticate())
            else:
                return redirect(next_page) if next_page else redirect(
                    url_for("home"))
        else:
            flash(
                "Login Unsuccessful. Check your email and password and try again!",
                "danger",
            )

    return render_template("login.html", title="Login", form=form)
Exemple #3
0
def login():
    # Checks that a logged user didn't somehow reach the login page.
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form_to_render = LoginForm()

    # Checks user credentials on a submitted form.
    if form_to_render.validate_on_submit():
        clinic = Clinic.query.filter_by(
            email=form_to_render.email.data).first()
        # If the user doesn't exist or the password doesn't match, throws error and returns to login.
        if clinic is None or not clinic.check_password(
                form_to_render.password.data):
            flash('Invalid email or password')
            return redirect(url_for('login'))

        # If everything checks out, log the user in (saves details to current_user).
        login_user(clinic, remember=form_to_render.remember_me.data)
        next_page = request.args.get('next')
        # Checks that next_page was not set to an absolute URL to prevent cross-site attacks
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)

    # If the request is GET, renders the login template.
    return render_template('login.html', title='Sign In', form=form_to_render)
Exemple #4
0
def user_login(request):
    err_msg = ''
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data.get('username'),
                                password=form.cleaned_data.get('password'))
            if user is not None:
                if user.is_active and user.get_profile().activated:
                    login(request, user)
                    return HttpResponseRedirect(
                        form.cleaned_data.get('next_url'))
                else:
                    err_msg = design.your_account_not_activated
            else:
                err_msg = design.invalid_login
    else:
        home_url = reverse('home')
        form = LoginForm(
            initial={'next_url': request.GET.get('next', home_url)})
    return render_to_response('login.html', {
        'form': form,
        'err_msg': err_msg
    },
                              context_instance=RequestContext(request))
Exemple #5
0
def home(request):
    # This view is missing all form handling logic for simplicity of the example
    if "POST" == request.method:
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return homepage(request, user)
                else:
                    print "password is valid but account is disabled"
            else:
                print "username and password are incorrect"
    else:
        if request.user.is_authenticated():
            user = get_user(request)

            return homepage(request, user)
        login_form = LoginForm()

    #if 'GET' == request.method:
    t = loader.get_template('main.html')
    c = RequestContext(request, {
        'login_form': login_form,
    })
    resp = t.render(c)

    return HttpResponse(resp)
Exemple #6
0
def login_view(request):
	redirect_url = request.GET.get('next', '/')
	# login is submitted
	if request.method == 'POST':
		# create form from request
		form = LoginForm(redirect_url, request.POST)
		# regular form validation
		if form.is_valid():
			# create instances
			u = form.cleaned_data['username']
			p = form.cleaned_data['password']
			user = authenticate(username=u, password=p)

			# information check
			if(user is not None):
				login(request, user)
				#url = settings.SITE_URL.replace('www', u) # create url
				try_to_connect_or_delete(request)
				return HttpResponseRedirect(form.cleaned_data['redirect'])
			else:
				form.errors['username'] = [u'User and password does not match!']
				return render_to_response(
								'register/login.html', {'form' : form},
								context_instance=RequestContext(request))
		# form is not valid
		else:
			return render_to_response(
							'register/login.html', {'form' : form},
							context_instance=RequestContext(request))
	
	form = LoginForm(redirect_url)
	return render_to_response(
					'register/login.html', {'form' : form},
					context_instance=RequestContext(request))
Exemple #7
0
def home(request):
    # This view is missing all form handling logic for simplicity of the example
    if "POST" == request.method:
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return homepage(request,user)
                else:
                    print "password is valid but account is disabled"
            else:
                print "username and password are incorrect"
    else:
        if request.user.is_authenticated():
            user = get_user(request)

            return homepage(request,user)
        login_form = LoginForm()


    #if 'GET' == request.method:
    t = loader.get_template('main.html')
    c = RequestContext(request,{'login_form': login_form,})
    resp = t.render(c)

    return HttpResponse(resp)
Exemple #8
0
def log_in(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
                username = form.cleaned_data['username']
                password = form.cleaned_data['password']
                users = authenticate(username=username, password=password)
                if users is not None:
                        login(request, users)
                        return redirect('profile', username)
                else:
                    try:
                        username = User.objects.get(email=username).username
                        users = authenticate(username=username, password=password)
                        if users is not None:
                            login(request, users)
                            return redirect('profile', username)
                    except:
                        pass
        return render_to_response('home.html', {'form': form}, context_instance=RequestContext(request))
    else:
        form = LoginForm()
        dic = {'form': form}
        dic.update(csrf(request))
        return render_to_response('login.html', dic)
Exemple #9
0
def url_login(request):
    uf = LoginForm(request.POST)
    msg = ''
    next = ''
    info = act_getinfo(request)
    if request.GET:  
       next = request.GET['next']
    if request.method == 'POST':
        if uf.is_valid():
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    info = act_getinfo(request)
                    if next == '':
                        return render(request, "main/right.html", {'info':info, 'username':username})
                    else:
                        return HttpResponseRedirect(next)
                else:
                    msg = _(u'Login failed, user is not active.')
                    return render(request, "main/login.html", {'info':info, 'uf':uf, 'msg':msg, 'next':next})
            else:
                msg = _(u'Guess what? Login failed.')
                return render(request, "main/login.html", {'info':info, 'uf':uf, 'msg':msg, 'next':next})
        else:
            msg = _(u'form not valid')
            return render(request, "main/login.html", {'info':info, 'uf':uf, 'msg':msg})
        # elif uf.is_valid():
        #     name=uf.cleaned_data['name']
        #     return render(request, 'main.test_result.html',{'uf':uf})
    else:
        return render(request, "main/login.html", {'info':info, 'uf':uf, 'msg':msg, 'next':next})
Exemple #10
0
def login_user(request):
    if not request.user:
        return HttpResponseRedirect('/index')
    if request.method == 'POST':
        form = LoginForm(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:
                if user.username == "admin" or not user.musician.banned:
                    auth_views.login(request, user)

                    if request.GET.get('next'):
                        return HttpResponseRedirect(request.GET['next'])
                    else:
                        return HttpResponseRedirect("/index")

                else:
                    error = "Your account have been banned"
                    return render(request, 'login.html',
                                  {'form': form, 'error': error})
            else:
                error = "Incorrect user or password"
                return render(request, 'login.html',
                              {'form': form, 'error': error})
        else:
            return render(request, 'login.html', {'form': form})
    else:
        form = LoginForm()
        return render(request, 'login.html', {'form': form})
Exemple #11
0
def login(request):
    if request.user.is_authenticated():
        return redirect('main.views.index')
    if request.POST:
        # load up the form with data from the POST request
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['email'],
                                password=form.cleaned_data['password'])
            if user is not None:
                django_login(request, user)
                fingr_user = user_to_fingr(request.user)
                notify_all_friends(fingr_user, 'Your friend ' + str(fingr_user.username) + ' has signed in')
                if user_to_fingr(user).verified:
                    notify_all_friends(fingr_user, 'Your friend ' + str(fingr_user.username) + ' has signed in')
                    # redirect to main page
                    return redirect('main.views.index')
                else:
                    django_logout(request)
                    #redirect to index page
                    return redirect('main.views.index')
    else:
        form = LoginForm()

    return render(request, 'login.html', {'form': form})
Exemple #12
0
def login(request, next=None):
    """Login user

    Keyword arguments:
    request -- request object
    next -- String

    Returns: HttpResponse

    """
    if next == None:
        if request.GET.get('next') == None:
            next = '/'
        else:
            next = request.GET.get('next')
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            username = data['username']
            password = data['password']
            user = auth.authenticate(username=username, password=password)
            if user is not None and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect(next)
    else:
        form = LoginForm()
    return {'form': form, 'next': next}
Exemple #13
0
def login(request, next = None):
    """Login user

    Keyword arguments:
    request -- request object
    next -- String

    Returns: HttpResponse

    """
    if next == None:
        if request.GET.get('next') == None:
            next = '/'
        else:
            next = request.GET.get('next')
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            username = data['username']
            password = data['password']
            user = auth.authenticate(username=username, password=password)
            if user is not None and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect(next)
    else:
        form = LoginForm()
    return {
        'form': form,
        'next': next
    }
Exemple #14
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data

        conn = sqlite3.connect('user.db')
        c = conn.cursor()
        c.execute("SELECT * FROM users WHERE username=?", (username, ))
        result = c.fetchone()

        if result is None:
            conn.commit()
            conn.close()
            flash('Login failed. Username does not exist')
            return redirect(url_for('index'))
        if username == result[0] and verify_password(result[1], password):
            session = request.cookies.get('session')
            c.execute("UPDATE users SET userSession=? WHERE username=?",
                      (session, username))
            conn.commit()
            conn.close()
            flash('User {} is logged-in.'.format(form.username.data))
            response = make_response(redirect(url_for('index')))
            response.set_cookie('username', username)
            response.set_cookie('userSession', session)
            return response
        else:
            conn.commit()
            conn.close()
            flash('Login failed. Wrong username or password.')
            return redirect(url_for('index'))
    return render_template('login.html', name='Login', form=form)
Exemple #15
0
def login_page(request):
    """
    Самописная функция авторизации

    :param request: объект c деталями запроса
    :type request: :class:`django.http.HttpRequest`
    :return: перенаправление на главную страницу
    """
    if request.method == 'POST':
        loginform = LoginForm(request.POST)
        if loginform.is_valid():
            username = loginform.data['username']
            password = loginform.data['password']
            user = authenticate(request, username=username, password=password)
            if user is not None:
                login(request, user)
                messages.add_message(request, messages.SUCCESS,
                                     "Авторизация успешна")
            else:
                messages.add_message(request, messages.ERROR,
                                     "Неправильный логин или пароль")
        else:
            messages.add_message(request, messages.ERROR,
                                 "Некорректные данные в форме авторизации")
    return redirect('index')
Exemple #16
0
def __login_view_post_failure(request):
    ip_address = get_client_ip(request)
    AuditEntry.objects.create(
        action="user_login_failed",
        ip=ip_address,
        username=request.POST["username"],
    )
    if "username" in request.COOKIES:
        form = LoginForm(initial={"username": request.COOKIES["username"]})
    else:
        form = LoginForm()
    try:
        user = fEMRUser.objects.get(username=request.POST["username"])
        if user.is_active:
            error_message = "Invalid username or password."
        else:
            error_message = (
                "Your account has been locked. Please contact your administrator."
            )
    except fEMRUser.DoesNotExist:
        error_message = "Invalid username or password."
    return render(
        request,
        "auth/login.html",
        {
            "error_message": error_message,
            "form": form
        },
    )
Exemple #17
0
def login_(request):
    student = None
    try:
        student = Student.objects.get(user = request.user)
    except:
        pass
    
    if student:
        return HttpResponseRedirect('/')
    
    error = list()
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            sid = form.cleaned_data['sid']
            pwd = form.cleaned_data['pwd']
            
            try:
                user = authenticate(username = sid, password = pwd)
                if not user:
                    error.append('Student can not match Password')
                else:
                    login(request, user)
                    student = Student.objects.get(user = user)
                    if len(error) == 0:
                        return HttpResponseRedirect('/')
            except:
                error.append('Login Failed')
    else:
        form = LoginForm()
    return render_to_response('login.html', RequestContext(request, locals()))
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.username.data == config.USERNAME and form.password.data == config.PASSWORD:
            return render_template('userauth.html', iscorrectuser=True)
        else:
            return render_template('userauth.html', iscorrectuser=False)
    return render_template('loginpage.html', form=form)
Exemple #19
0
def user_login(request):
	form = LoginForm(request.POST or None)
    	if request.POST and form.is_valid():
        	user = form.login(request)
        	if user:
            		login(request, user)
            		return HttpResponseRedirect('/main/home')# Redirect to a success page.
	return render(request, 'main/index.html', {'form': form })
Exemple #20
0
def login(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            auth.login(request, form.cleaned_data['user'])
            return redirect(request.GET.get('next', 'home'))
    else:
        form = LoginForm()
    return render(request, "login.html", {'form': form})
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash(
            f"Login success for {form.username.data} with password length of: {len(form.password.data)}!",
            "success",
        )
        return redirect(url_for("home"))
    return render_template("login.html", title="Login", form=form)
Exemple #22
0
def login():
	form = LoginForm()
	if form.validate_on_submit():
		if form.email.data == "*****@*****.**" and form.password.data == "Hse220793":
			flash('You have been logged in!', "success")
			return redirect(url_for('home'))
		else:
			flash('Login unsucessful, please check email and password', "danger")
	return render_template("login.html", form=form)
Exemple #23
0
def login(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            auth.login(request, form.cleaned_data['user'])
            return redirect(request.GET.get('next', 'home'))
    else:
        form = LoginForm()
    return render(request, "login.html", {'form': form})
Exemple #24
0
def signup(request, template="main/register.html"):
    """
    Signup form.
    """
    """
    Login form.
    """
    login_form = LoginForm(prefix="login")
    #DriverImageFormSet = formset_factory(CarImageForm, max_num=6)
    signup_form = ProfileForm()
    #formset = DriverImageFormSet
    if request.method == "POST":
        #import pdb;pdb.set_trace()

        login_form = LoginForm(request.POST, prefix="login")
        signup_form = ProfileForm(request.POST, request.FILES)
        #import pdb;pdb.set_trace()
        

        if not login_form.has_changed() and not request.POST.get("from_popup",False): login_form = LoginForm(prefix="login")
        if not signup_form.has_changed(): signup_form = ProfileForm()
        
        if login_form.is_valid():
            authenticated_user = login_form.save()
            messages.info(request, _("Successfully logged in"))
            auth_login(request, authenticated_user)
            
            return redirect('/')

        if signup_form.has_changed() and signup_form.is_valid():
            #formset = DriverImageFormSet(request.POST, request.FILES)
            new_user = signup_form.save()
            Driver(user=new_user).save()
            
            #import pdb;pdb.set_trace()
            #
            #data = signup_form.cleaned_data
            #import pdb;pdb.set_trace()
#            f_img = Image.objects.create(image=request.FILES.get('featured_image'))
#            driver = Driver.objects.create(user=new_user, mobile=data.get('mobile',None), featured_image=f_img, sex=data.get('gender'))#set mobile and featured image
            
            
#            if formset.is_valid():
#                for form in formset: 
#                    cd = form.cleaned_data
#                    if cd:
#                        dci = DriverImage(driver=driver, image=cd.get('image'))
#                        dci.save()

            
            messages.info(request, _("Successfully signed up!"))
            auth_login(request, new_user)
            return redirect("/")
    #import pdb;pdb.set_trace()
    context = {"login_form": login_form, "signup_form": signup_form}
    return render(request, template, context)
Exemple #25
0
def login(request):
    username = "******"
    if request.method == "POST":
        MyLoginForm = LoginForm(request.POST)
        if (MyLoginForm.is_valid()):
            username = MyLoginForm.cleaned_data['username']
    else:
        MyLoginForm = LoginForm()
    return render(request, 'main/template/loggedin.html',
                  {'username': username})
Exemple #26
0
def signup(request, template="main/register.html"):
    """
    Signup form.
    """
    """
    Login form.
    """
    login_form = LoginForm(prefix="login")
    signup_form = ProfileForm()
    if request.method == "POST":
        login_form = LoginForm(request.POST, prefix="login")
        signup_form = ProfileForm(request.POST)
        if not login_form.has_changed() and not request.POST.get(
                "from_popup", False):
            login_form = LoginForm(prefix="login")
        if not signup_form.has_changed(): signup_form = ProfileForm()

        if login_form.is_valid():
            authenticated_user = login_form.save()
            messages.info(request, "Successfully logged in")
            auth_login(request, authenticated_user)

            return redirect('/')

        if signup_form.has_changed() and signup_form.is_valid():
            #import pdb;pdb.set_trace()
            new_user = signup_form.save()
            messages.info(request, "Successfully signed up")
            auth_login(request, new_user)
            return redirect("/")

    context = {"login_form": login_form, "signup_form": signup_form}
    return render(request, template, context)
Exemple #27
0
def index(request, template_name='main/index.html'):
    page_title = 'Welcome To Country Sports Bet'
    form = LoginForm()
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=request.POST.get('username'),password=request.POST.get('password'))
            if user and user.is_active:
                login(request,user)
                return HttpResponseRedirect(urlresolvers.reverse('bet'))
    return render_to_response(template_name,locals(),context_instance=RequestContext(request))
Exemple #28
0
def index(request, template_name="main/index.html"):
    page_title = "Welcome To Country Sports Bet"
    form = LoginForm()
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=request.POST.get("username"), password=request.POST.get("password"))
            if user and user.is_active:
                login(request, user)
                return HttpResponseRedirect(urlresolvers.reverse("bet"))
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
Exemple #29
0
def logInReq(request):
    if request.method == 'POST':
        log = LoginForm(request.POST)
        if log.is_valid():
            try:
                user = Users.objects.get(email=log.cleaned_data.get('email'),
                                         pwd=log.cleaned_data.get('pwd'))
                request.session['user_id'] = user.id
                return HttpResponseRedirect(reverse('main:index'))
            except Users.DoesNotExist:
                return HttpResponse("WRONG USERNAME OR PASSWORD")
Exemple #30
0
def login_view(request):
    print(request.session.get('org_id'))

    if request.method != 'POST':
        return render(request, 'main/login.html', {'form': LoginForm()})

    form = LoginForm(request.POST)
    if form.is_valid():
        return login_execute(request, form)
    else:
        return render(request, 'main/login.html', {'form': form})
Exemple #31
0
    def post(self, request):
        form = LoginForm(request.POST)
        context = {
            'model_name': 'Login',
            'form': form
        }

        if form.is_valid():
            login(request, user=form.auth)
            return redirect("dashboard")

        return render(request, self.login_template, context=context)
Exemple #32
0
    def post(self, request):
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['login'],
                                password=form.cleaned_data['password'])
            if user:
                login(request, user)
                if user.is_staff:
                    return redirect('/admin/')
                return redirect('dashboard')

        return render(request, 'main/login.html')
Exemple #33
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = models.UserInfo.query.filter_by(loginname=form.username.data).first()
        if user is not None and user.verifypassword(form.password.data):
            login_user(user, form.remember_me.data)
            branch = models.BranchInfo.query.filter_by(branchid=user.branchid).first()
            # todo 调整session存储
            session['branchname'] = branch.cname
            session['username'] = user.username
            return redirect(request.args.get('next') or url_for('main.index'))
        flash('Invalid username or password!')
    return render_template('main/login.html', form=form)
Exemple #34
0
 def post(self, request):
     form = LoginForm(request.POST)
     if not form.is_valid():
         return render(request, "login.html", {"form": form})
     user = authenticate(request=request,
                         username=form.cleaned_data['username'],
                         password=form.cleaned_data['password'])
     if user is None:
         # messages.add_message(request, messages.WARNING, 'Profil o podanych danych nie istnieje.')
         return redirect('login')
     login(request, user)
     # messages.add_message(request, messages.SUCCESS, 'Zostałeś poprawnie zalogowany.')
     return redirect('main')
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check email and password', 'danger')
    return render_template('login.html', title='Login', form=form)
def login():
    form = LoginForm()
    messages = []
    if request.method == 'POST' and form.validate_on_submit():
        user = Users.query.filter(
            or_(Users.username == form.username.data,
                Users.email == form.username.data)).first()
        if user:
            if bcrypt.check_password_hash(user.password, form.password.data):
                login_user(user, remember=form.remember.data)
                return redirect(url_for('index'))
        messages.append('Username/Email or password wrong')
    return render_template('login.html', form=form, messages=messages)
Exemple #37
0
    def dispatch(self, request, *args, **kwargs):
        form = LoginForm(data = request.POST or None)
        if form.is_valid():
            user = authenticate(username = form.cleaned_data['username'], password = form.cleaned_data['password'])
            if user:
                if user.is_active:
                        auth_login(request, user)
                        return redirect("home")

        context = {
              'form': form
        }
        return render(request, self.template_name, context)
Exemple #38
0
 def post(self, request):
     form = LoginForm(request.POST)
     if form.is_valid():
         user = authenticate(username=form.cleaned_data['login'],
                             password=form.cleaned_data['password'])
         if user:
             login(request, user)
             return redirect('/')
         else:
             return render(request, 'main/login.html', {
                 'form': form,
                 'error': 'Brak użytkownika o podanym loginie'
             })
Exemple #39
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(account=form.account.data).first()
        if user and user.account == user.password:
            login_user(user)
            flash('請設定新密碼', 'danger')
            return redirect(url_for('reset'))
        elif user and user.password == form.password.data:
            login_user(user, remember=form.remember.data)
            return redirect(url_for('home'))
        else:
            flash('帳號或密碼錯誤', 'danger')
    return render_template('account.html', form=form, title='登入系統')
Exemple #40
0
def logInReq(request):
    if request.method == 'POST':
        log = LoginForm(request.POST)
        if log.is_valid():
            try:
                em = log.cleaned_data.get('email')
                pw = log.cleaned_data.get('pwd')
                print(em)
                print(pw)
                user = Users.objects.get(email=em, pwd=pw)
                request.session['user_id'] = user.id
                # return render(request,'Temp/dashboard.html')
                return HttpResponseRedirect(reverse('main:checknow'))
            except Users.DoesNotExist:
                return HttpResponse("WRONG USERNAME OR PASSWORD")
Exemple #41
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html', title='Sign In', form=form)
def home(request):
    # form = LoginForm(request.POST or request.session.get('login') or None)
    form = LoginForm(request.POST or None)
    data = None
    if form.is_valid():
        # request.session['login'] = form.cleaned_data
        mi_telcel = MiTelcel(**form.cleaned_data)
        mi_telcel.login()
        data = mi_telcel.get_saldos()
        mi_telcel.logout()

    return render_to_response('home.html', {
        'form': form,
        'data': data,
    }, RequestContext(request))
def legacy_login(request):
    
    if request.method == 'POST':
        form = LoginForm(data=request.POST)
        
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
        
            if user is not None:
                auth_login(request, user)
                return HttpResponseRedirect('/')

    return HttpResponseRedirect('/')
Exemple #44
0
def login(request):
    register_form = RegisterForm()
    if request.method == "POST":
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            cdata = login_form.cleaned_data
            user = authenticate(email=cdata.get("email"), 
                                password=cdata.get("password"))
            if user:
                dj_login(request, user)
                return HttpResponseRedirect(request.COOKIES.get("next", "/"))
            messages.error(request, _("Wrong email or password "))

    else:
        login_form = LoginForm()
    return render_to_response("auth/login_or_register.jinja", locals())
Exemple #45
0
def login(request, template="main/register.html"):
    """
    Login form.
    """
    loginform = LoginForm(prefix="login")
    signup_form = ProfileForm(prefix="signup")
    if request.method == "POST":
        #import pdb;pdb.set_trace()

        loginform = LoginForm(request.POST, prefix="login")
        if loginform.is_valid():
            authenticated_user = loginform.save()
            messages.info(request, _("Successfully logged in"))
            auth_login(request, authenticated_user)            
            return redirect('home')
    context = {"loginform": loginform, "signup_form": signup_form}
    return render(request, template, context)
Exemple #46
0
def login(request):
    login_form = LoginForm()
    if request.method == "POST":
        login_form = LoginForm(request.POST)

        if login_form.is_valid():
            username = request.POST.get("username")
            password = request.POST.get("password")
            user = authenticate(username=username, password=password)
            _login(request, user)
            return HttpResponseRedirect("/")
 
        
    ctx = {
        "login_form" : login_form
    }
    return render_to_response("login.html", context_instance=RequestContext(request, ctx) )
Exemple #47
0
def login(request):
    login_form_errors = {}
    if request.method == 'GET':
        login_form = LoginForm()
    elif request.method == 'POST':
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            cd = login_form.cleaned_data
            user = auth.authenticate(username=cd['login'], password=cd['password'])
            if user is not None and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect("/repository/")
            else:
                login_form._errors["login"] = login_form.error_class([u'Ошибка при авторизации'])
        login_form_errors = {field: login_form._errors[field].as_text()[2:] for field in login_form._errors}

    return render_to_response('login.html', {'login_form_errors': login_form_errors}, context_instance=RequestContext(request))
Exemple #48
0
def user_login(request):
    err_msg = ''
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data.get('username'), password=form.cleaned_data.get('password'))
            if user is not None:
                if user.is_active and user.get_profile().activated:
                    login(request, user)
                    return HttpResponseRedirect(form.cleaned_data.get('next_url'))
                else:
                    err_msg = design.your_account_not_activated
            else:
                err_msg = design.invalid_login
    else:
        home_url = reverse('home')
        form = LoginForm(initial={'next_url': request.GET.get('next', home_url)})
    return render_to_response('login.html', {'form': form, 'err_msg': err_msg }, context_instance=RequestContext(request))
Exemple #49
0
def main(request, template_name='main/main.html'):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            try:
                hero = Hero.objects.get(login=form.cleaned_data['login'],
                                        password=hashlib.sha1(
                                    form.cleaned_data['password']).hexdigest())
                request.session['hero_id'] = hero.id
                return HttpResponseRedirect(reverse('hero'))
            except Hero.DoesNotExist:
#
                messages.add_message(request, messages.ERROR,
                                     'Hero doesn\'t exist.')
    else:
        form = LoginForm()

    variables = RequestContext(request, {'form': form})

    return render_to_response(template_name, variables)
Exemple #50
0
def LoginRequest(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("/profile/")
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            users = authenticate(username=username, password=password)
            if users is not None:
                login(request, users)
                return redirect("sesion")
            else:
                return render_to_response("home.html", {"form": form}, context_instance=RequestContext(request))
        else:
            return render_to_response("home.html", {"form": form}, context_instance=RequestContext(request))
    else:
        """ user is not submitting the form, show the login form """
        form = LoginForm()
        context = {"form": form}
        return render_to_response("home.html", context, context_instance=RequestContext(request))
Exemple #51
0
def LoginRequest(request):
        if request.user.is_authenticated():
                return HttpResponseRedirect('/profile')
        if request.method == 'POST':
                form = LoginForm(request.POST)
                if form.is_valid():
                        username = form.cleaned_data['username']
                        password = form.cleaned_data['password']
                        users = authenticate(username=username, password=password)
                        if users is not None:
                                login(request, users)
                                return redirect('account')
                        else:
                                return render_to_response('home.html', {'form': form}, context_instance=RequestContext(request))
                else:
                        return render_to_response('home.html', {'form': form}, context_instance=RequestContext(request))
        else:
                ''' user is not submitting the form, show the login form '''
                form = LoginForm()
                context = {'form': form}
                return render_to_response('home.html', context, context_instance=RequestContext(request))
Exemple #52
0
def signIn(request):
    form = LoginForm()
    message = ''
    if not request.POST:
        return render(request,'signin.html', {'form': form, 'message': message})
    form = LoginForm(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:
            return redirect('/group/')
            if user.is_active:
                login(request, user)
                return redirect('/group/')
            else:
                message = 'Извините, данный аккаунт заблокирован'
        else:
            message = 'Неверный email/пароль'
    else:
        message = 'suck'
    return render(request,'signin.html', {'form': form, 'message': message})
Exemple #53
0
def login(request):
    if request.method == 'POST':
        if request.is_ajax():
            form = LoginForm(request.POST)
            if form.is_valid():
                auth_login(request, form.get_user())
                data = {'logged_in': True}
            else:
                data = {
                    'logged_in': False,
                    'errors': {
                        k: [e for e in v] for k, v in form.errors.items()
                    }
                }

            return JSONResponse(data)

    data = {
        'logged_in': False,
    }

    return JSONResponse(data)