def on_get_user(cmd: pcmd.Command, args: List[str], uname: str, force: bool) -> None: """Callback for `get user` - gets user info""" u = db.get_user(uname) if force or not u: u = public.get_user(uname) u.print_info()
def signup(): if request.method == 'GET': #return '<form action="/" method="POST"><input name="email"><input type="summit"></form>' # return render_template('index.html') return render_template('signup.html') email = request.form['email'] user = request.form['name'] password = request.form['password'] token = s.dumps(email, salt='email-confirm') data = db.get_user(email, "email") if data['email'] == email: flash("You are rigistered user. Please login") return redirect('/login') results = db.add_user({ 'email': email, 'user': user, 'password': password, "email_confirmation": None }) msg = Message('Confirm Email', sender='*****@*****.**', recipients=[email]) link = url_for('confirm_email', token=token, _external=True) msg.body = 'Your link is {}'.format(link) mail.send(msg) return '<h1> The email you endered is {}. The token is {} </h1>'.format( email, token)
def handle_get_vk_user(vk_user_id: int): vk_user_id = int(vk_user_id) acct = context.accounts.get(vk_user_id) if acct: return acct # inactive/unknown acct = context.accounts[vk_user_id] = dict(db.get_user(vk_user_id)) return acct
def confirm_email(token): try: email = s.loads(token, salt='email-confirm', max_age=3600) except SignatureExpired: return '<h1> The token is Expired <\h1>' data = db.get_user(email, "email") if data['email_confirmation']: flash('User already verified successfully! please login') else: data['email_confirmation'] = "verified" results = db.update_user(data) flash('User has been verified successfully') return render_template('users.html')
def login(): if request.method == 'GET': return render_template('login.html') user = request.form.get('username') password = request.form.get('password') remember = True if request.form.get('remember') else False if user and password and request.method == 'POST': data = db.get_user(user, "user") if data['user'] == user and data['password'] == password: #return jsonify("You are successfully loged in") return redirect('/login?next=' + request.url) flash("You username or password incorrect") return redirect('/login') else: return not_found()
def on_find(cmd: pcmd.Command, args: List[str], uname: str, substr: str) -> None: """Callback for `find` - gets all of a user's answers containing a substring""" substr = substr.lower() u = db.get_user(uname) print(uname) res = db.fetchall( 'SELECT a.* FROM answers a INNER JOIN users u ON a.user = u.id WHERE u.uname = ? AND (LOWER(a.answer) LIKE ? OR LOWER(a.tell) LIKE ?)', uname, '%' + substr + '%', '%' + substr + '%') match = re.compile(substr, re.IGNORECASE) repma = lambda s: match.sub( cr.Fore.LIGHTMAGENTA_EX + substr + cr.Fore.RESET, s) print(' Matches:') for a in [Answer(*r[:-2], u, r[-1]) for r in res]: print(' -> [Q]: %s || [A]: %s || [%s]' % (repma( a.tell or ''), repma(a.answer or ''), a.created.isoformat())) print(' A total of %s%d%s answers by %s%s%s match the current substring.' % (cr.Fore.LIGHTGREEN_EX, len(res), cr.Fore.RESET, cr.Fore.LIGHTCYAN_EX, uname, cr.Fore.RESET))
finally: client.disconnect() if __name__ == "__main__": if len(sys.argv) < 2: print( 'Usage:', os.path.basename(__file__), '<vk user id> [<tg channel id> [<vk group id> <tg message id> [<tg message id> ...]]]' ) exit(1) args = dict(zip(('vk_id', 'tg_id', 'vk_gid'), sys.argv[1:4])) message_ids = [] if len(sys.argv) < 5 else list(map(int, sys.argv[4:])) vkuser = db.get_user(args['vk_id']) if not vkuser: print('Unknown vk user id') exit(1) if not vkuser['access_token']: print('VK token is invalid') exit(1) if not vkuser['phone_number']: print('VK user phone number not set') exit(1) loop = uvloop.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(run(vkuser, message_ids))
def load_user(id): return db.get_user("_id", id)