async def user_register(request): if request.method == 'POST': name = request.form.get('name', '') phone = request.form.get('username', '') password = request.form.get('pwd', '') pwd = Users().passwd(password) code = request.form.get('user_code', '') admin = Users.get(Users.phone == phone) if admin: content = """<html> <script> alert("该用户已注册"); window.location.href='http://{0}/change_pwd'; </script> </html> """.format(request.host) return response.html(content) else: #默认注册账号为1级代理 users = Users() users.username = name users.phone = phone users.password = pwd users.level = 1 users.user_code = uuid.uuid4() if code == "": users.agent_id = 0 else: invite_user = users.get(user_code=code) users.agent_id = invite_user.id users.save() balance = Balance() balance.username = name balance.phone = phone balance.amount = 0 balance.commission = 0 user = Users().get(Users.phone == phone) balance.user_id = user.id balance.save() content = """ <html> <script> alert("注册成功"); window.location.href='http://{0}/login'; </script> </html> """.format(request.host) return response.html(content) else: user_code = request.args.get("user_code", "") return jinja.render("admin/change_pwd.html", request, user_code=user_code, message="")
def setUp(self): """ Method called to prepare the test fixture """ self.newUser = Users() self.register = self.newUser.user_register("*****@*****.**", "mwaz", "password", "password") app.config['TESTING'] = True self.test_app = app.test_client()
async def login(request): if request.method == 'POST': username = request.form.get('username', '') password = request.form.get('password', '') #用户名和密码长度,类型等验证, pwd = Users().passwd(password) admin = Users.get(Users.phone == username, Users.password == pwd) if admin: keys = [ 'show_id', 'username', 'phone', 'is_admin', 'level', 'id', 'agent_id' ] cookies = admin.to_dict(keys) cookies_json = set_cookies(COOKIE_TOKEN, cookies) res = response.text(ujson.dumps({'login': '******', 'code': 1})) res.cookies['user'] = cookies_json res.cookies["user"]["max-age"] = 36000 return res else: res = response.text( ujson.dumps({ 'login': '******', 'code': 0, 'info': '登录失败:用户名或密码错误' })) return res else: return jinja.render("admin/login.html", request, message="")
def user_score_based_recommend(self, users, target_user): """ @data: data is a list of recommend contents's ids """ engine = UserScoreBasedRecommendEngine(self) data = engine.run(Users(users), User(target_user)) return data
def register(): if request.method == "POST": userName = request.form.get("username") userEmail = request.form.get("email").lower() userPassword = request.form.get("password") userConfirmPassword = request.form.get("confirmation") # Check lenght of password if len(userPassword) <= 5: return apology("Password is too short", 400) if checkUserInfo(userName, userEmail, userPassword, userConfirmPassword) == True: hashPassword = generate_password_hash(userPassword) newUser = Users(name=userName, email=userEmail, password=hashPassword) try: db.session.add(newUser) db.session.commit() session["user_id"] = newUser.id session["email"] = newUser.email return redirect("/") except IntegrityError as e: # Check if User already exist in DB by email # return errorhandler(e) alternative variant from server eror return apology("Email already exist", 400) else: return apology( checkUserInfo(userName, userEmail, userPassword, userConfirmPassword)) else: # GET return render_template("register.html")
def init_user(): user = Users() user.username = "******" user.phone = "17830466355" user.is_admin = 1 user.level = 1 user.password = user.passwd("466355") user.save()
def init_balance(): balance = Balance() balance.username = "******" balance.phone = "17830466355" balance.amount = 0 balance.commission = 0 user = Users().get(Users.phone == "17830466355") balance.user_id = user.id balance.save()
async def agent_info(request): ''' 个人信息展示 :param request: :return: ''' if request.method == 'GET': cookie = request.cookies.get("user") user = get_cookies(AGENT_COOKIE_TOKEN, cookie) user_id = user.get("id") query = Users().select().filter(Users.deleted == 0, Users.id == user_id) code = Users().get(id=user_id) invite_url = "http://{}/change_pwd/?user_code={}".format( request.host, code.user_code) return jinja.render("admin/user_info.html", request, data=query, invite_url=invite_url)
def get_or_create_user(user_id): user = db_session.query(Users).filter_by(id=user_id).first() if not user: profile = line_bot_api.get_profile(user_id) user = Users(id=user_id, nick_name=profile.display_name, image_url=profile.picture_url) db_session.add(user) db_session.commit() return user
async def alipay_notify(request): if request.method=='POST': _data = request.form data={} for key in _data.keys(): data.update({key:_data.get(key)}) signature = data.pop("sign") # verify success = _alipay.verify(data, signature) if success and data["trade_status"] in ("TRADE_SUCCESS","TRADE_FINISHED"): invoice_amount = float(data['invoice_amount']) trade_no = data.get('out_trade_no') order = PayOrders.get(PayOrders.out_trade_no==trade_no) user_id = order.user_id if order.status==0: order.status = 1 order.save() old = Balance().get(Balance.user_id==user_id) Balance().update({"amount":old.amount+float(invoice_amount)}).where(Balance.user_id == user_id).execute() # 首次充值邀请加10元 if PayOrders().filter(PayOrders.user_id==user_id,PayOrders.status==1).count()==1: user = Users().get(Users.id == user_id) if user.agent_id !=0: detail = "你邀请ID为{}的首冲奖励".format(user_id) Commission().create(user_id=user.agent_id, from_user_id=user_id, once_amount=10, detail=detail) agent_old_balance = Balance.get(Balance.user_id == user.agent_id) Balance().update({Balance.commission: agent_old_balance.commission + 10}).where( Balance.user_id == user.agent_id).execute() return response.html("<html><center><h1>支付成功</h2></center></html>") else: return response.html("<html><center><h1>支付失败</h2></center></html>") else: data = dict(request.query_args) signature = data.pop("sign") success = _alipay.verify(data, signature) if success and data["trade_status"] in ("TRADE_SUCCESS","TRADE_FINISHED"): trade_no = data.get('out_trade_no') order = PayOrders.get(PayOrders.out_trade_no==trade_no) if order.status==0: order.status = 1 order.save() return response.html("<html><center><h1>支付成功</h2></center></html>") else: return response.html("<html><center><h1>支付失败</h2></center></html>")
def update_user(self, user_id, data): ''' 修改 :param show_id: :param data: :return: ''' user = Users.get(Users.id == user_id) if "username" in data and data.get("username").strip(): user.username = data.get("username") if "phone" in data and data.get("phone").strip(): user.phone = data.get("phone") if "password" in data and data.get("password").strip(): user.password = Users().passwd(data.get('password')) if "level" in data and data.get("level").strip(): user.level = data.get("level") user.save()
def render_template(self, view_filename, params=None): if not params: params = {} cookie_law = self.request.cookies.get("cookie_law") if cookie_law: params["cookies"] = True user = users.get_current_user() if user: params["user"] = user new_user = Users(email=user.email(), name="Test") new_user.put() params["logout_url"] = users.create_logout_url('/') else: params["login_url"] = users.create_login_url('/') template = jinja_env.get_template(view_filename) return self.response.out.write(template.render(params))
def register(): """Router for register page.""" if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): picture_file = save_picture(form.picture.data) current_user.image_file = picture_file hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = Users(username=form.username.data, email=form.email.data, image_file=picture_file, password=hashed_password) db.session.add(user) db.session.commit() flash( f'Аккаунт {form.username.data} успешно зарегистрирован! Войдите в систему.', 'success') return redirect(url_for('login')) return render_template('register.html', title='Регистрация', form=form)
def create_account(name: str, email: str, passwd: str) -> Users: user = Users(name=name, email=email, passwd=passwd) user.save() return user
parser.add_argument('-s', '--send', help="Message to send") parser.add_argument('-H', '--history', action="store_true", help="History of conversation beetween 2 users") args = parser.parse_args() # Scenarios: # 1. -u -p -E -e <-- creating new user/ updating existing user # 2. -u -p -d <-- removing user (if exists in TABLE) # 3. -l <-- list of all users # 4. -u -p -s -t <-- send message from logged user to another user (both have to exist) # 5. -F -t -H <-- show full history of conversation beetween two users cnx, cursor = create_connection() # creating object to work on user = Users() # creating new user to database users if args.username and args.password and args.email and args.edit: user.id = user.get_id(args.username, cursor) user.save_to_db(args.username, args.password, args.email, cursor) # removing user(if exists) if args.username and args.password and args.delete: user.id = user.get_id(args.username, cursor) user.validate_data(args.username, args.password, cursor) if user.id != -1 or user.validate_data(args.username, args.password, cursor): user.delete(cursor) print("Account has been deleted !") else:
for db in dblist: print(db) # CREATE OR TAKE THE DATABASE "Example_IA" mydb = myclient["Example_IA"] if "Example_IA" in dblist: print("database already exist!") print("initialize data...") # CREATE COLLECTIONS (users, books) users = mydb["users"] books = mydb["books"] #CREATE NEW USER (admin) admin = Users(users, "admin") admin.password = "******" admin.save() #CREATE NEW USER (phil) phil = Users(users, "phil") phil.password = "******" phil.email = "*****@*****.**" phil.save() #CREATE NEW BOOK (phil) LotR = Books(books, "Lord of the ring") LotR.author = "Tolkien" LotR.description = "One ring to rule them all" LotR.save()
def lambda_handler(event, context): params = json.loads(event['body']) u = Users('test') return respond(200, {'greeting': f'hello {params["name"]}!'})
"""The vierws.py file deals with the logic used by the classes""" import os from flask import render_template, request, session, g, Flask from models.user import Users from models.recipe import Recipe from models.categories import Categories app = Flask(__name__) from app import app app.secret_key = os.urandom(24) # needed to keep the client sessions secure new_user = Users() # instance of class Users new_cat = Categories() # instance of class Category new_recipe = Recipe() # instance of class Recipe @app.route('/') def index(): """ Redirects to the index page """ return render_template('index.html') @app.route('/register', methods=['GET', 'POST']) def register(): """Handles the view for user registration, it then fetches the return messages in the register methods and returns appropriate messages to the user through the templates""" if request.method == "POST": # gets the email, password, password and confirm password from the # registration.html template