def GET(self): print web.ctx.method id = web.input().id print id model.update_user(id) o = dict(r=0) return simplejson.dumps(o)
def GET(self): print web.ctx.method id = web.input().id print id model.update_user(id) o = dict(r = 0) return simplejson.dumps(o)
def make_user(username, password): existing = model.get_user(username) if existing: print "Updating existing user" model.update_user(username, password) else: print "Creating new user" model.add_user(username, password)
def POST(self, uid,cin, key): i = web.input() user = model.get_user_by_id(cin, uid)[0] form = self.form() if form.validates(): pwd = bcrypt.hashpw(i.password, bcrypt.gensalt(BCRYPT_WLOAD)) model.update_user(cin, uid, pwd, user.email, user.privilege) raise web.seeother('/login') else: raise web.seeother('/passwordchange/%d/%d/%s') %(uid, cin, key)
def edit_profile(): session_user_email = session['username'] if request.method == 'POST': new_first_name = request.form['first_name'] new_last_name = request.form['last_name'] query = 'UPDATE users SET first_name=%s, last_name=%s WHERE email = %s' values = (new_first_name, new_last_name, session_user_email) model.update_user(query, values) flash('Edited Successfuly!') return redirect(url_for('profile')) return render_template('edit.html')
def POST(self): web.header('Access-Control-Allow-Origin','*') web.header('Access-Control-Allow-Credentials', 'true') data = web.input() profilepicname=data['profilepic_name'] coverpicname=data['coverpic_name'] fn=data['firstname'] ln=data['lastname'] abt=data['about'] ph=data['phone'] eml=data['email'] un=data['username'] db=data['dob'] cntry=data['country'] if profilepicname!="": fout = open('static/profilepic' +'/'+ profilepicname,'w') fout.write(data['profilepic_file']) fout.close() if coverpicname!="": fout = open('static/coverpic' +'/'+ coverpicname,'w') fout.write(data['coverpic_file']) fout.close() s=model.update_user('static/profilepic/' + profilepicname,'static/coverpic/' + coverpicname,fn,ln,ph,eml,un,db,cntry,abt) return s
def _action_battle_report(cid, user, content, update, context): """ Update user info from battle report """ if settings.VERBOSE: print(" Battle report") try: user.cw_name = content.split(settings.GUILD_NAME)[1].split( b' \\u2694:')[0].decode("unicode_escape") user.cw_level = int( content.split(b' Lvl: ')[1].split(b'\\n')[0].decode( "unicode_escape")) if user.cw_name and user.cw_level: if model.user_by_id(update.effective_user.id): status = model.update_user(user) else: status = model.subscribe(user) if settings.VERBOSE: print(" {0} Lvl: {1} Status: {2}".format( user.cw_name, user.cw_level, status)) except Exception as e: utils._admin_error(context, "_action_battle_report: battle report", user=user, error=str(e))
def update(id): if request.method == "POST": if update_user(id, request.form['username'], request.form['email'], request.form['password']): return '<h1>Updated</h1><br> <a href="/login">Voltar</a>' else: return '<h1>Something Wrong</h1><br> <a href="/login">Voltar</a>' return render_template('update.html')
def update_profile(): global current_user if 'username' in session: username = session['username'] current_user = model.get_user(username) logging.debug("update_profile: Trying (%s)" % (username)) if current_user.username == "administrator": flash("Profile updating has been disabled for user admin.", 'error') return render_template('profile.html', current_user=current_user) new_name = html.escape(request.form['name']) if not new_name: new_name = current_user.name new_about = html.escape(request.form['about']) if new_name == 'None': new_about = None new_photo = request.files['photo'] if not new_photo: new_photo_filename = current_user.photo else: new_photo_filename = ''.join( random.choices(string.ascii_lowercase + string.digits, k=8)) + '_' + new_photo.filename new_photo_filename = html.escape(new_photo_filename) new_photo.save(app.config['photos_folder'] + new_photo_filename) logging.debug("update_profile: filename (%s)" % new_photo_filename) logging.debug("update_profile: file (%s)" % new_photo) current_password = hashPassword( html.escape(request.form['currentpassword'])) new_password = hashPassword(html.escape(request.form['newpassword'])) if not new_password: new_password = current_password if current_password != current_user.password: flash("Current password does not match registered password.", 'error') return render_template('profile.html', current_user=current_user) try: current_user = model.update_user(username, new_name, new_password, new_about, new_photo_filename) except Exception as e: logging.debug("update_profile: Found exception(%s)" % e) return error(e) logging.debug("update_profile: Succesful (%s)" % (username)) if current_user: flash("Succesfully updated user %s profile" % username, ) return render_template('profile.html', current_user=current_user)
def POST(self, uid,cin, key): i = web.input() user = model.get_user_by_id(cin, uid)[0] form = self.form if form.validates(): pwd = bcrypt.hashpw(i.password, bcrypt.gensalt(BCRYPT_WLOAD)) model.update_user(cin, uid, pwd, user.email, user.privilege) raise web.seeother('/login') else: try: recovery = model.get_recovery_time(cin, userid, key)[0] t = timedelta(days=1) d1, d2 = datetime.utcnow(), datetime.utcfromtimestamp(recovery.timestamp) if d2 + t > d1: return render.passwordchange(form, user, key, d2+t) else: raise web.notfound('Link has expired') except IndexError: raise web.notfound()
def PUT(self, user_id): data = json.loads(web.data()) updated_user = model.update_user(data) if updated_user: user = model.get_user_by_id(data['id']) user['registerDate'] = str(user['registerDate']) return json.dumps(user) else: web.ctx.status = '500 Internal Server Error' return
def POST(self): postdata = web.input(fileselect2={}) if postdata.formaction == 'changeuserpic': uploadedfile = postdata.fileselect2 filename = uploadedfile.filename splitfilename = filename.split(os.extsep, 1) extension = splitfilename[1] if extension in ['jpg', 'png', 'gif', 'jpeg']: newfilename = str(uuid.uuid4()) filedir = rootdir + '/static/profilepics' newfile = open(filedir + '/' + newfilename + '.' + extension,'w') newfile.write(uploadedfile.file.read()) newfile.close() model.update_user_picture(session.userid, newfilename + '.' + extension) else: pass #no message sent to front end yet raise web.seeother('/adminmyaccount') elif postdata.formaction == 'changeme': model.update_user(session.userid, postdata.useremail, postdata.userfirstname, postdata.userlastname) raise web.seeother('/adminmyaccount')
def craft_reset(update, context): """ Reset craft operation """ global CACHE cid=update.message.chat.id # validate user if not utils._check_user(context, update.effective_user.id, cid): return tmp=update.message.text.split(" ") if len(tmp)>1: if tmp[1]=="yes": # reset users for user in model.users(): user.crafting="{}" status=model.update_user(user) # reset guild CACHE["guild"]={"resources": {}, "parts": {}, "recipes": {}} context.bot.send_message(chat_id=cid, text="Crafting operation restarted...", parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True) else: user=model.user_by_id(tmp[1]) if user: user.crafting="{}" status=model.update_user(user) context.bot.send_message(chat_id=cid, text="Crafting operation restarted [{1}]... for @{0}".format(html.escape(user.username), status), parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True) else: context.bot.send_message(chat_id=cid, text='Type "/craft_reset <i>yes</i>" to reset all operation and stored data', parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True)
def me(): # My details page, allows users to update their basic information. message = None log_access('me') if request.method == 'POST': model.update_user(request.form) log_access('me', 'saved form') message = "Saved." if request.form['username'] != session['user_username']: auth.remove_auth() return redirect(url_for('me')) form=model.get_user(session['user_id']) return render_template('user_edit.html', form=form, message=message, user_auth_levels=get_authorization_levels(session['user_auth_level']), form_action_url=url_for('me'), title="My Details", delete_button = False, change_password_button = True)
def edit_user(username): # Edits information of a user. if session['user_auth_level'] >= 1000 or session['user_username'] == username: log_access('users/edit', 'editing: ' + username) message = None if request.method == 'POST': log_access('users/edit', 'posted form') model.update_user(request.form) message = "Saved." form=model.get_user_by_username(username) return render_template('user_edit.html', form=form, message=message, user_auth_levels=get_authorization_levels(session['user_auth_level']), form_action_url=url_for('edit_user', username=username), title="Edit User", delete_button = session['user_auth_level'] >= 1000, change_password_button = not config.USES_PUBCOOKIE) else: log_access('users/edit', 'access_denied editing: ' + username) return redirect(url_for('access_denied'))
def _action_deposit(cid, user, content, update, context): """ Modify amount of items after deposit """ item = b' '.join(content.split(b' ')[2:-1]).decode()[10:] amount = int(content.split(b' ')[-1][1:-1]) print(" Deposit: {0} x ({1})".format(item, amount)) item = utils.item_by_name(item) if item: item_type = "" if item["code"].startswith('r'): item_type = "recipes" elif item["code"].startswith('k'): item_type = "parts" # modify the crafting data if item_type: # guild warehouse if item["name"].lower() in CACHE["guild"][item_type]: CACHE["guild"][item_type][item["name"].lower()] += amount else: CACHE["guild"][item_type][item["name"].lower()] = amount # user u = model.user_by_id(update.effective_user.id) if u: crafting = json.loads(u.crafting) if crafting and len(crafting.keys()): if item["name"].lower() in crafting[item_type]: crafting[item_type][item["name"].lower()] -= amount if crafting[item_type][item["name"].lower()] < 1: del crafting[item_type][item["name"].lower()] # store data user.crafting = json.dumps(crafting) if model.user_by_id(update.effective_user.id): status = model.update_user(user) if not status: utils._admin_error(context, "_action_deposit", user=user, error="update: False", trace=False) else: utils._admin_error(context, "_action_deposit", user=user, error="no registered user", trace=False)
def _action_crafting_list(cid, user, content, update, context): """ Update crafting list """ print(" Crafting tab") data = {"parts": {}, "recipes": {}, "datetime": None} today = datetime.datetime.today().isoformat() for c in content.split(b'\\n'): tmp = c # check false positive messages if b':' in tmp: continue # recipe if c.startswith(b'\\U0001f4c3'): # tmp=c.split(b'\\U0001f4c3')[1].split(b' /view_r')[0] tmp = c.split(b'\\U0001f4c3')[1].split(b' /i_r')[0] tmp = tmp.split(b' (') if len(tmp) == 2 and tmp[1].endswith(b')'): c_name = tmp[0].decode().lower() c_amount = int(tmp[1][:-1]) data["recipes"][c_name] = c_amount data["datetime"] = today # part elif c.startswith(b'\\U0001f9e9'): tmp = c.split(b'\\U0001f9e9')[1].split(b' (') if len(tmp) == 2 and tmp[1].endswith(b')'): c_name = tmp[0].decode().lower() c_amount = int(tmp[1][:-1]) data["parts"][c_name] = c_amount data["datetime"] = today if data["datetime"]: user.crafting = json.dumps(data) if model.user_by_id(update.effective_user.id): status = model.update_user(user) if not status: utils._admin_error(context, "_action_crafting_list", user=user, error="update: False", trace=False) else: utils._admin_error(context, "_action_crafting_list", user=user, error="no registered user", trace=False)
def PUT(self, id): """Update a user""" data = web.data() data = demjson.decode(data) model.update_user(id, data['email'], data['password']) return demjson.encode(model.get_user(id))