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")
def login(): form = UserPasswordForm(request.form) if form.validate_on_submit() and request.method == 'POST': # check password and redirect to admin home from BusTrack import app print("form.username.data is ", form.password.data, " admin username ", app.config['ADMIN_USERNAME']) if app.config['ADMIN_USERNAME'] == form.username.data and SessionHelper.is_password_correct(app.config['ADMIN_PASSWORD'], form.password.data): session['is_admin_login'] = True return redirect(request.args.get('next') or url_for('admin.index')) else: flash('incorrect credentials') render_template('admin/login.html', form=form) return render_template('admin/login.html', form=form)
def driver(): # handle driver tasks form = AddDriverForm(request.form) # TODO : Disable add when no bus unallocated (for now using front-end logic) un_alloc = Bus.unallocated_bus() if form.validate_on_submit() and request.method == 'POST': # if 'bus' not in request.form: # TODO: later add option for update d = Driver(user_id=form.username.data, bus_id=request.form['bus'] , name=form.name.data, contact=form.contact.data, password=SessionHelper.get_password_hash(form.password.data)) d.add() # clear fileds form.username.data = form.name.data = form.contact.data = '' # return render_template('admin/driver.html',form=form) alloc_driver = Driver.get_all_allocated() return render_template('admin/driver.html', form=form, bus_data=un_alloc, driver_list=alloc_driver)