Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
def createUser(name, email, password):
	user = User()
	user.name = name
	user.email = email
	user.password = password
	user.active = True

	return user.save()
Exemple #4
0
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)
Exemple #5
0
    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
Exemple #6
0
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)
Exemple #7
0
def doLogin():
    user = request.form['u']
    pwd = request.form['p']
    user = User.authenticate(user, pwd)
    return jsonify(user) if user else abort(401)
Exemple #8
0
def doLogout():
    login_key = request.form['login_key']
    r = User.get_redis()
    r.delete(login_key)
    return jsonify({'res': User.logout(login_key)})
Exemple #9
0
	def test_getByName(self):
		u = User()
		user =  u.getByName('ipedrazas')
		uid  = user.get('id')
		print user
		# print u.addPicture(uid, '4fb120ce2ba78b09f7000048')
Exemple #10
0
def createUser(name, email, password):
	User.create(name, email, password, 'script')