def perform_login(self): """ Main method to be called that handles login logic """ if self.user is None: raise ValueError( "user object is null,pass it on class constructor.") if 'username' not in self.user or 'password' not in self.user: return { 'status': 'error', 'message': 'must provide username and password in request json body.' } user = self.get_user() if user is None: return {'status': 'error', 'message': 'Invalid credentials.'} # create new api token and update for this user user.api_token = rand(40) self.db.commit() return { 'status': 'ok', 'email': user.email, 'phone': user.phone, 'token': user.api_token }
def kid(): form = AddKidForm(request.form) if form.validate_on_submit() and request.method == 'POST': if 'bus' in request.form: rand_pass = utils.rand(6) # store parent and get its unique id to store it in Kid table # BUT BUT ,if parent already register then don't re-register instead add this kid to previously added parent p = Parent(name=form.parent_name.data, password=rand_pass, email=form.email.data) p_id = p.add_or_get() k = Kid(name=form.kid_name.data, section=form.kid_section.data, bus_id=request.form['bus'], parent_id=p_id) from sqlite3 import IntegrityError k.add() # clear form field form.parent_name.data = form.email.data = form.kid_name.data = form.kid_section.data = form.parent_name.data = '' # TODO: Send this generated password to Parent email else: all_parent_kid = Parent.get_all_parent_kid_with_bus() all_bus = Bus().get_all() return render_template('admin/kid.html', form=form, bus_data=all_bus, bus_error='Must Select a Bus', all_parent_kid=all_parent_kid) all_parent_kid = Parent.get_all_parent_kid_with_bus() all_bus = Bus().get_all() return render_template('admin/kid.html', form=form, bus_data=all_bus, all_parent_kid=all_parent_kid)
def login(): js = request.json if js is not None: if 'username' in js and 'password' in js: email = js['username'] _pass = js['password'] parent = Parent.get_user(email) if parent is None: return make_response( jsonify(status='error', message='invalid user'), 403) name = parent[1] phone = parent[3] pass_hash = parent[4] if pass_hash is not False and SessionHelper.is_password_correct( pass_hash, _pass): # ok correct user m_token = utils.rand(40) m_expire = utils.get_expiry_date_full() # update this token Parent.update_token(email, m_token, m_expire) return jsonify(status='ok', message='ok login', token=m_token, expires=m_expire, name=name, phone=phone, email=email) else: return make_response( jsonify(status='error', message='invalid user'), 403) else: return jsonify(status='error', message='incorrect parameters') else: return jsonify(status='error', message='only json body is allowed')
def login(): # require username,password as json js = request.json if js is not None: if 'username' in js and 'password' in js and 'journey_type' in js: u_id = js['username'] _pass = js['password'] j_type = js['journey_type'] # validate j_type if j_type not in [0, 1]: return jsonify(status="error", message="Incorrect journey type") user = Driver.get_user(u_id) if not user: return make_response( jsonify(status='error', message='Invalid Credential'), 403) name = user[0] pass_hash = user[1] bus_no = user[2] if pass_hash is not False and SessionHelper.is_password_correct( pass_hash, _pass): # ok correct user # make sure, if similar ride is not already completed by this driver if Driver.is_ride_already_completed(u_id, j_type): return jsonify(status='error', message='ride already completed for today.') # get active ride active_ride = user[3] # generate a random token m_token = utils.rand(40) m_expire = utils.get_expiry_date_full() Driver.update_token(m_token, m_expire, u_id) if active_ride is None or active_ride is '': # no active session, start new session # and create new journey and set it bus_id = user[4] Journey.trans_create_journey(j_type, utils.get_date_full(), bus_id, u_id) else: # no need to create new journey pass return jsonify(status="ok", message="Correct Credentials", token=m_token, valid_till=m_expire, name=name, bus=bus_no) else: return make_response( jsonify(status="error", message="Invalid Credential"), 403) else: return jsonify(status="error", message="Incorrect Request") else: return jsonify(status="error", message="Only Json Body is allowed")