def setImageUser(): user_id = request.form['user_id'] image_url = request.form['image_url'] if is_valid_id(user_id): User.add_picture({'_id': ObjectId(user_id)}, image_url) return jsonify({'response': 'ok'}) return abort(404)
def getUserByName(key=None): if key is None: abort(404) u = User.get_by_name(key) if u: return jsonify({'user': u}) else: user = User.get_user(key) if user: return jsonify({'user': json.loads(user)}) else: abort(404)
def createUser(name, email, password): user = User() user.name = name user.email = email user.password = password user.active = True return user.save()
def newUser(): user = request.form['user'] pwd = request.form['pwd'] code = request.form['code'] email = request.form['email'] m = Manager() res = dict() if m.validateCode(code): u_id = User.create(user, email, pwd, code) if u_id: res = {'id': u_id} else: res = {'error': 'Username/email is already in use'} else: res = {'error': 'Code is not valid'} return jsonify(res)
def insert(self, name, owner, ui, type, read, write, button): if User.is_admin(owner): current_app.logger.info('Is admin') now = datetime.utcnow() slug = slugify(name) control_id = objects.insert({'n': name, 'c': now, 'u': 'system', 's': slug, 'tx': type}) ui = self.replace_values(ui, str(control_id), name, type, slug) button = self.replace_values(button, str(control_id), name, type, slug) read = self.replace_values(read, str(control_id), name, type, slug) write = self.replace_values(write, str(control_id), name, type, slug) view = {'r': read, 'w': write} d = {'default': view} objects.update({'_id': control_id}, {'$set': {'ui': ui, 'v': d, 'bt': button}}) return str(control_id) current_app.logger.info('No admin') return False
def add_user_to_group(): key = request.form['login_key'] bid = request.form['blibb_id'] username = request.form['username'] user = get_key(key) res = dict() if is_valid_id(bid): user_to_add = User.get_by_name(username) if user_to_add: if Blibb.can_write(user, '', bid): Blibb.add_user_to_group(username, bid) res['result'] = 'ok' else: res['error'] = 'Not permissions' else: res['error'] = 'User not found' else: res['error'] = 'Object Id is not valid' return jsonify(res)
def doLogin(): user = request.form['u'] pwd = request.form['p'] user = User.authenticate(user, pwd) return jsonify(user) if user else abort(401)
def doLogout(): login_key = request.form['login_key'] r = User.get_redis() r.delete(login_key) return jsonify({'res': User.logout(login_key)})
def test_getByName(self): u = User() user = u.getByName('ipedrazas') uid = user.get('id') print user # print u.addPicture(uid, '4fb120ce2ba78b09f7000048')
def createUser(name, email, password): User.create(name, email, password, 'script')