def update(self): "Update processor information" # Load ip = h.getRemoteIP() processor = Session.query(model.Processor).filter(model.Processor.ip == ip).first() # If the processor doesn't exist, if not processor: processor = model.Processor(ip) Session.add(processor) # Update processor.when_updated = datetime.datetime.utcnow() Session.commit()
def login_(self): "Process login credentials" # Check username username = str(request.POST.get("username", "")) person = Session.query(model.Person).filter_by(username=username).first() # If the username does not exist, if not person: return dict(isOk=0) # Check password password_hash = model.hashString(str(request.POST.get("password", ""))) # If the password is incorrect, if password_hash != StringIO.StringIO(person.password_hash).read(): # Increase and return rejection_count without a requery rejection_count = person.rejection_count = person.rejection_count + 1 Session.commit() return dict(isOk=0, rejection_count=rejection_count) # If there have been too many rejections, if person.rejection_count >= parameter.REJECTION_LIMIT: # Expect recaptcha response recaptchaChallenge = request.POST.get("recaptcha_challenge_field", "") recaptchaResponse = request.POST.get("recaptcha_response_field", "") recaptchaKey = config["safe"]["recaptcha"]["private"] # Validate result = captcha.submit(recaptchaChallenge, recaptchaResponse, recaptchaKey, h.getRemoteIP()) # If the response is not valid, if not result.is_valid: return dict(isOk=0, rejection_count=person.rejection_count) # Get minutesOffset from UTC minutesOffset = h.getMinutesOffset() # Save session session["minutesOffset"] = minutesOffset session["personID"] = person.id session["nickname"] = person.nickname session.save() # Save person person.minutes_offset = minutesOffset person.rejection_count = 0 Session.commit() # Return return dict(isOk=1)