def search(): u = db.get_user_by_name(request.form['name']) if not u: return render_template('error.html', msg='Sorry, we could not find a user named ', white=request.form['name']) return redirect(url_for('public', id=u['_id']))
def on_photo(client, dev, command, params, message): logging.info("on_photo %s"%(dev.devid())) type = 'jpg' if not ( isinstance(params, list) and len(params)>=2): logging.warn('photo params error') return sid = params[1] if len(params)>=3: type=params[2] url = save_photo_file(message, type) if not url: logging.warn('upload photo failed,url='+url) return if( isinstance(params, list) and len(params)==0 ): return user = db.get_user_by_name(params[0]) if not user: user = db.get_user(dev.get_record().device_master) if not user: logging.warn('no user for %s'%(params[0])) return photoid = db.insert_photo(dev, '%s'%([user.user_id]), url) if not photoid: logging.warn('insert photo db error') return notification.photo(dev.imei, photoid, [user], url, params[1], dev.get_record().device_name) pass
def index(): #En caso de que el usuario no haya iniciado sesion if 'public_key' not in session or session['public_key'] == None: return redirect(url_for('login')) else: #Obtener monedas del user coins = get_galactic_coins(session['public_key']) if session['username'] == 'Darth Vader': #Users para transferir coins users = get_users() #Armas para la venta weapons = get_weapons(session['public_key']) return render_template('index.html', users=users, coins=coins, weapons=weapons, isAdmin=True) else: darth_vader = get_user_by_name('Darth Vader') weapons = get_weapons(darth_vader['public_key']) #Renderizar index return render_template('index.html', coins=coins, weapons=weapons, isAdmin=False)
def create(): if request.method == "POST": username = request.form["username"] password = request.form["password"] # Whether there is the same user name if db.get_user_by_name(username) is None: db.add_user(username, password) session["username"] = username return render_template("index.html", username=session["username"]) return render_template("create.html")
def transform_review(): reviews = json.load(open(BASE_PATH + 'tripadvisor_reviews' + SUFFIX, 'r')) for review in reviews: data = { 'user': get_user_by_name(review['user']), 'outlet_id': get_outlet_by_id_outlet(review['id_outlet']), 'date': convert_date(review['date']), 'review': review['body'], 'rating': review['rating'] } insert_review(data)
def register(): if request.method == 'GET': return render_template('register.html') elif request.method == 'POST': form = request.form username = form.get('username') email = form.get('email') password = form.get('password') exist_user = db.get_user_by_name(username) if exist_user: return render_template('register.html', message='Name already been used!') else: db.create_new_user(username, email, password) return redirect('/login')
def on_voice(client, dev, command, params, message): logging.info("on_voice %s" % (dev.devid())) url = save_voice_file(message) if not url: logging.error('upload voice failed') return dur = (len(message) + 800) / 1600 users = dev.get_users() if len(users) == 0: logging.info('not found users for device %s' % (dev.imei)) return if (params and isinstance(params, list) and len(params) > 0): targets = params[0].split(',') app_users = [] family_users = [user.user_name for user in users] others = [] for target in targets: x = [user for user in users if user.user_name == target] if x: app_users.append(x[0]) else: x = db.get_user_by_name(target) if x: app_users.append(x) else: others.append(target) if app_users: vocid = db.insert_voice( 'd%s' % (dev.imei), 'u%s' % ([user.user_name for user in app_users]), url, dur) if vocid: notification.new_voice(dev.imei, vocid, app_users, url, dur, dev.get_record().device_name) for target in others: odev = db.get_device_record_by_phone(target) if odev: vocid = db.insert_voice('d%s' % (dev.imei), 'd%s' % (odev.device_imei), url, dur) client.publish(odev.device_imei, 'voc', ('%s' % (dev.get_record().device_phone), '%s' % (vocid)), bytearray(message)) else: vocid = db.insert_voice('d%s' % (dev.imei), 'u%s' % ([user.user_name for user in users]), url, dur) notification.new_voice(dev.imei, vocid, users, url, dur, dev.get_record().device_name) pass
def login(): if request.method == 'GET': return render_template('login.html', user_valid='', pass_valid='') elif request.method == 'POST': form = request.form username = form.get('username') password = form.get('password') valid_user = db.get_user_by_name(username) if valid_user: if valid_user['password'] == password: session['loggedin'] = True session['username'] = username session['ids'] = str(valid_user['_id']) return redirect('/') else: return render_template('login.html', user_valid='', password_valid='Wrong password!') else: return render_template('login.html', user_valid='user not exist', pass_valid='')
def get_user(self): if not self.user: username = ''.join( [random.choice(string.printable) for i in KEYSEQ]) self.set_user(db.get_user_by_name(username, True)) return self.user