Skip to content

Commit

Permalink
Merge branch 'master' into pages
Browse files Browse the repository at this point in the history
  • Loading branch information
n.lyubchich committed Jul 22, 2015
2 parents 5a2f094 + 053244e commit faad916
Show file tree
Hide file tree
Showing 10 changed files with 1,213 additions and 245 deletions.
14 changes: 2 additions & 12 deletions project/admin/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import Blueprint, render_template, url_for, session, g, redirect
from flask import Blueprint, render_template, url_for, session, redirect
from project.admin.forms import VacancyForm, CategoryForm, CityForm
from project.admin.utils import EntryDetail, EntryList
from project.auth.forms import RegisterForm, UserEditForm
from project.auth.forms import RegisterForm
from project.models import Vacancy, Category, City, User

SECTIONS = {} # list_name: list_endpoint
Expand All @@ -10,15 +10,6 @@
admin_app = Blueprint('admin', __name__)


@admin_app.before_request
def add_login_to_g():
if 'user_id' in session:
user = User.query.get(session['user_id'])
g.user = user
else:
g.user = None


@admin_app.before_request
def check_user_logged_in():
if 'user_id' in session:
Expand Down Expand Up @@ -130,7 +121,6 @@ def register_section(*, section_name, list_endpoint,
user_detail = EntryDetail.as_view(
name='user_detail',
create_form=RegisterForm,
update_form=UserEditForm,
model=User,
success_url="user_list",
)
Expand Down
27 changes: 14 additions & 13 deletions project/auth/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask_wtf import Form
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired, EqualTo, Email, Length
from .validators import LoginFormat, PasswordFormat, Exists
from .validators import LoginFormat, PasswordFormat, Exists, PasswordCorrect


class ResetForm(Form):
Expand Down Expand Up @@ -74,13 +74,21 @@ class RegisterForm(Form):
)


class UserEditForm(RegisterForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class PasswordEditForm(Form):
old_password = PasswordField(
label='Старый пароль',
validators=[
PasswordCorrect(),
]
)

password = PasswordField(
label='Пароль',
new_password = PasswordField(
label='Новый пароль',
validators=[
EqualTo(
'confirmation',
message='Пароли не совпадают'
),
PasswordFormat,
Length(
6,
Expand All @@ -90,10 +98,3 @@ def __init__(self, *args, **kwargs):
]
)
confirmation = PasswordField(label='Подтвердите пароль')

def validate(self):
super(UserEditForm, self).validate()
EqualTo(
'confirmation',
message='Пароли не совпадают'
)(self, self.password)
11 changes: 11 additions & 0 deletions project/auth/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from wtforms.validators import Regexp, ValidationError
from project.models import User
from werkzeug.security import check_password_hash
from flask import g

# alphanumeric and special chars (-_.)
# Can not start with a digit, underscore or special character
Expand All @@ -18,6 +20,15 @@
' содержать хоть одну цифру')


class PasswordCorrect(object):
def __init__(self, message=None):
self.message = message or 'Неверный пароль'

def __call__(self, _, field):
if not check_password_hash(g.user.password, field.data):
raise ValidationError(self.message)


class Exists(object):
def __init__(self, message=None, reverse=False):
if message:
Expand Down
31 changes: 28 additions & 3 deletions project/auth/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from flask import render_template, Blueprint, flash, session, redirect, \
url_for, abort, g
from .forms import LoginForm, ResetForm
from .forms import LoginForm, ResetForm, PasswordEditForm
from .decorators import login_required
from project.models import User

auth = Blueprint('auth', __name__)


@auth.before_app_request
def add_login_to_g():
if 'user_id' in session:
user = User.query.get(session['user_id'])
g.user = user
else:
g.user = None


@auth.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
Expand All @@ -15,12 +24,12 @@ def login():
if user:
session['user_id'] = user.id
g.user = user
return redirect(url_for('admin.vacancy_list'))
return redirect(url_for('admin.mainpage'))
else:
flash("Неправильный логин и/или пароль")

if session.get('user_id'):
return redirect(url_for('admin.vacancy_list'))
return redirect(url_for('admin.mainpage'))

return render_template(
'login.html',
Expand Down Expand Up @@ -56,6 +65,22 @@ def confirm_reset(token):
abort(404)


@auth.route('/password_change', methods=['GET', 'POST'])
@login_required
def change_password():
form = PasswordEditForm()
if form.validate_on_submit():
User.bl.set_password(form.data['new_password'])
flash('Ваш пароль успешно изменён')
return redirect(url_for('admin.mainpage'))
return render_template(
'login.html',
title='Смена пароля',
submit='Сменить',
form=form,
)


@auth.route('/logout', methods=['GET'])
@login_required
def logout():
Expand Down
8 changes: 0 additions & 8 deletions project/bl/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ def create(self, data):
model.save()
return model

def update(self, data):
model = self.model
for key, value in data.items():
setattr(model, key, value)
model.bl.set_password(data['password'])
model.save()
return model

def forgot_password(self, email):
from project.models import Token
from .mail import send_mail
Expand Down
50 changes: 36 additions & 14 deletions project/static/css/feed.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
width: 30px;
height: 30px;
margin-left: 9px;
margin-top: 7.5px;
margin-top: 6%;
float: left;
}
.vacancyTitle {
Expand All @@ -11,12 +11,42 @@
text-align: center;
margin-top: 8px;
margin-right: 25px;
font-family: sans-serif;
font-family: sans-serif !important;
}


.vacancyTitle > a {
color: #000000;
font-family: sans-serif
}

.vacancyTitle > a:hover {
color: #123456;

text-decoration: none;
}

.vacancyDescr {
margin-left: 15%;
font-family: sans-serif;
margin-right: 11%;
margin-top: 20px;
font-size: 16px;
}

.vacancyCity {
margin-left: 4%;
font-family: sans-serif;
display: inline;
width: 80%;
font-size: 20px;
}

.vacancySalary {
float: right;
display: inline;
margin-right: 11%;
font-size: 20px !important;
}

.panel {
Expand All @@ -25,14 +55,6 @@
width: 100%;
}

.vacancyNodeCompressed, .vacancyNodeExpanded {

}

.vacancyNodeCompressed {
height: 70px;
}

.vacancyBox {
width: 400px;
margin: 20px;
Expand Down Expand Up @@ -112,13 +134,13 @@
}

.btn-circle {
width: 30px;
height: 30px;
width: 35px;
height: 35px;
text-align: center;
padding: 6px 0;
font-size: 12px;
font-size: 13.125px;
line-height: 1.428571429;
border-radius: 15px;
border-radius: 17.5px;
}

.btn-circle.btn-lg {
Expand Down

0 comments on commit faad916

Please sign in to comment.