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)
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)
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)
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)
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render( request, 'gallery/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): context = { 'page_title': 'Register'} registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'profile_pics' in request.FILES: profile.prof_pic = request.FILES['profile_pics'] profile.save() registered = True else: print(user_form.error, profile_form.error) else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'pages/register.html', { 'user_form':user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): if request.user.is_authenticated: return redirect('gallery:home') registered = False if request.method == 'POST': user_form = UserForm(request.POST) profile_form = UserProfileForm(request.POST, request.FILES) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() profile = profile_form.save(commit=False) profile.user = user profile.save() registered = True else: user_form = UserForm() profile_form = UserProfileForm() return render( request, 'pages/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered, 'page_title': 'Register' })
def new_user(): form = UserForm() return render_template('admin/users/new.html', title=u'Добавить пользователя', form=form)