def doLogin(): username, password = request.form['username'], request.form['password'] try: user_info = userModel.login(username, password) session["loged_user"] = user_info return json.dumps({'status': 200, 'msg': 'OK', 'data': user_info}) except Exception as e: print(e) return json.dumps({'status': -1, 'msg': e.message})
def login(): """Logs in as a customer, manager or carpenter Returns: template: the UI to be displayed products: list of products len: number of products """ if 'customer' in session and session['customer']: return redirect(request.url_root) elif 'manager' in session and session['manager']: return redirect(request.url_root + "manager") else: session.clear() page = request.args.get('page') if not request.form or not 'username' in request.form or not 'password' in request.form: return render_template('login.html'), 400 user_details = user.login(request.form['username'], request.form['password']) if (user_details): url = "" session['user_name'] = request.form['username'] session['fname'] = user_details['FirstName'] session['lname'] = user_details['LastName'] if user_details['Role'] == "Carpenter": session['carpenter'] = True result = order.get_all_orders() if len(result) > 0: for orders in result: orders['order_date'] = orders['order_date'].strftime( '%m-%d-%Y') result.reverse() return render_template('woodworker.html', orders=result, len=len(orders), url=url), 200 elif user_details['Role'] == "Admin": session['manager'] = True return redirect(request.url_root + "manager") else: session['customer'] = True return redirect(request.url_root) else: return render_template('login.html', error="Invalid credentials. Try again!!!"), 401
def test_correct_login(self): result = user.login('*****@*****.**', 'password') self.assertEqual(result['ID'], 45)
def test_wrong_email_login(self): result = user.login('*****@*****.**', 'password') self.assertEqual(result, None)
def user_logout(): user.login()