Beispiel #1
0
def edit_user(id):
    key = db.Key(id)
    user = User.get(key)
    form = UserForm(request.form, user)
    form.key.data = key
    return render_template('admin/users/edit.html',
                           title=u'Редактировать пользователя',
                           form=form,
                           user=user)
Beispiel #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = RegisterForm()
    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data.lower()
        username = form.username.data
        password = form.password.data
        user = User(name=name, email=email, username=username)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        token = generate_token(user=user, operation='confirm')
        send_confirm_email(user=user, token=token)
        flash('Confirm email sent, check your inbox.', 'info')
        return redirect(url_for('.login'))
    return render_template('auth/register.html', form=form)
Beispiel #3
0
def modify(request):

    if request.method == 'POST':
        data = json.loads(request.body)
        name = data["name"]
        lastName = data["lastName"]
        email = data["email"]
        country = data["country"]
        city = data["city"]
        pws = data["password"]
        id = data["idUser"]
        _user = User()
        if (_user.update(id, name, lastName, email, country, city, pws)):
            res = {"status": "Ok", "Content:": "Usuario Modificado"}
        else:
            res = {"status": "Error", "Content:": "Error al modificar usuario"}

        return HttpResponse(json.dumps(res), content_type="application/json")
    else:
        return HttpResponse('Metodo no definido')
Beispiel #4
0
def update_user(id):
    key = db.Key(id)
    user = User.get(key)
    form = UserForm(request.form, user)
    form.key.data = key
    if form.validate():
        form.populdate_obj(user)
        user.put()
        flash('Пользователь успешно сохранен', 'correct')
        redirect(url_for('edit_user', id=user.key()))
    else:
        return render_template('admin/users/edit.html', title=u'Редактировать пользователя', form=form, user=user)
Beispiel #5
0
def create(request):

    if request.method == 'POST':
        data = json.loads(request.body)
        name = data["name"]
        lastName = data["lastName"]
        email = data["email"]
        login = data["login"]
        country = data["country"]
        city = data["city"]
        pws = data["password"]
        id = data["idUser"]
        image = data["image"]
        _user = User(name=name,
                     lastName=lastName,
                     email=email,
                     login=login,
                     country=country,
                     city=city,
                     password=pws,
                     idUser=id,
                     image=image)
        try:
            user = User.objects.filter(idUser=id)
            if not user:
                _user.save()
                res = {"status": "Ok", "Content:": "Usuario creado"}
            else:
                return HttpResponse('user already exists', status=401)

        except:
            res = {"status": "Error", "Content:": "Error al crear usuario"}

        return HttpResponse(json.dumps(res), content_type="application/json")
    else:
        return HttpResponse('Metodo no definido')
Beispiel #6
0
def update_user(id):
    key = db.Key(id)
    user = User.get(key)
    form = UserForm(request.form, user)
    form.key.data = key
    if form.validate():
        form.populdate_obj(user)
        user.put()
        flash('Пользователь успешно сохранен', 'correct')
        redirect(url_for('edit_user', id=user.key()))
    else:
        return render_template('admin/users/edit.html',
                               title=u'Редактировать пользователя',
                               form=form,
                               user=user)
Beispiel #7
0
def create_user():
    user = User()
    form = UserForm(request.form, user)
    form.key.data = None
    if form.validate():
        form.populate_obj(user)
        user.password_salt = str(hashlib.md5(os.urandom(124)))
        user.password_hash = str(
            hashlib.md5(form.password.data + user.password_salt).hexdigest())
        user.put()
        flash('Пользователь успешно сохранен', 'correct')
        return redirect(url_for('edit_user', id=user.key()))
    else:
        return render_template('admin/users/new.html',
                               title=u'Добавить пользователя',
                               form=form)
Beispiel #8
0
def create_user():    
    user = User()    
    form = UserForm(request.form, user)
    form.key.data = None
    if form.validate():
        form.populate_obj(user)
        user.password_salt = str(hashlib.md5(os.urandom(124)))
        user.password_hash = str(hashlib.md5(form.password.data + user.password_salt).hexdigest())
        user.put()
        flash('Пользователь успешно сохранен', 'correct')
        return redirect(url_for('edit_user', id=user.key()))
    else:
        return render_template('admin/users/new.html', title=u'Добавить пользователя', form=form)
Beispiel #9
0
def edit_user(id):
    key = db.Key(id)
    user = User.get(key)
    form = UserForm(request.form, user)
    form.key.data = key    
    return render_template('admin/users/edit.html', title=u'Редактировать пользователя', form=form, user=user)
Beispiel #10
0
def users():
    users = User.all()
    return render_template('admin/users/index.html', title=u'Пользователи', users=users)
Beispiel #11
0
	def validate_email(form, field):
		user= User.all().filter('email = ', field.data).get()
		if user is not None and form.key.data != user.key():
			raise ValidationError('Такой Электронный адрес уже существует')
Beispiel #12
0
	def validate_login(form, field):
		user = User.all().filter('login = '******'Такой Логин уже существует')
Beispiel #13
0
 def validate_email(form, field):
     user = User.all().filter('email = ', field.data).get()
     if user is not None and form.key.data != user.key():
         raise ValidationError('Такой Электронный адрес уже существует')
Beispiel #14
0
 def validate_login(form, field):
     user = User.all().filter('login = '******'Такой Логин уже существует')
Beispiel #15
0
def users():
    users = User.all()
    return render_template('admin/users/index.html',
                           title=u'Пользователи',
                           users=users)
Beispiel #16
0
    def setUp(self):
        app = create_app('testing')
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()
        self.runner = app.test_cli_runner()

        db.create_all()
        Role.init_role()

        admin_user = User(email='*****@*****.**',
                          name='Admin',
                          username='******',
                          confirmed=True)
        admin_user.set_password('123')
        normal_user = User(email='*****@*****.**',
                           name='Normal User',
                           username='******',
                           confirmed=True)
        normal_user.set_password('123')
        unconfirmed_user = User(email='*****@*****.**',
                                name='Unconfirmed',
                                username='******',
                                confirmed=False)
        unconfirmed_user.set_password('123')
        locked_user = User(email='*****@*****.**',
                           name='Locked User',
                           username='******',
                           confirmed=True,
                           locked=True)
        locked_user.set_password('123')
        locked_user.lock()

        blocked_user = User(email='*****@*****.**',
                            name='Blocked User',
                            username='******',
                            confirmed=True,
                            active=False)
        blocked_user.set_password('123')

        photo = Photo(filename='test.jpg',
                      filename_s='test_s.jpg',
                      filename_m='test_m.jpg',
                      description='Photo 1',
                      author=admin_user)
        photo2 = Photo(filename='test2.jpg',
                       filename_s='test_s2.jpg',
                       filename_m='test_m2.jpg',
                       description='Photo 2',
                       author=normal_user)

        comment = Comment(body='test comment body',
                          photo=photo,
                          author=normal_user)
        tag = Tag(name='test tag')
        photo.tags.append(tag)
        db.session.add_all([
            admin_user, normal_user, unconfirmed_user, locked_user,
            blocked_user
        ])
        db.session.commit()