Exemple #1
0
    def form_valid(self, form):
        data = form.cleaned_data

        birth = datetime(day=int(data['day']),
                         month=int(data['month']),
                         year=int(data['year']))
        if data['avatar'] == 'default':
            data[
                'avatar_url'] = 'https://drive.google.com/uc?id=1Sq-iC4JD1Be3J9HZ2d13YdswF5EOMbEl&export=download'
        else:
            filename = f"{data['nickname']}_avatar.png"
            with open(filename, 'wb') as f:
                for chunk in data['avatar'].chunks():
                    f.write(chunk)

            data['avatar_url'] = self.drv.add_file(filename).get(
                "webContentLink")

            remove(filename)

        user = User(nickname=data['nickname'],
                    first_name=data['first_name'],
                    birth_date=birth,
                    password=data['password'],
                    avatar=data['avatar_url'])
        user.save()
        return redirect('index')
Exemple #2
0
def register(request):
    email = request.POST.get("email")
    password = request.POST.get("password")
    name = request.POST.get("name")
    address = request.POST.get("address")
    # Generate a salt, hash the password, and store information in the database.
    password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(14))
    u = User(name=name, password=password, email=email, address=address)
    try:
        u.save()
        return JsonResponse({'status': 'good', 'data': {
            'name': u.name,
            'staff': u.is_staff
        }})
    except Exception, e:
        return JsonResponse({'status': 'bad', 'message': 'Email is already registered'})
Exemple #3
0
def create_user(lastName, firstName, login=None, password=None, phoneNumber=None, vkId=None, permissions=None):
    user = User(lastName=lastName, firstName=firstName)
    if login:
        user.login = login
    if password:
        user.password = password
    if phoneNumber:
        user.phoneNumber = phoneNumber
    if vkId:
        user.vkId = vkId
    if permissions:
        user.permissions = permissions
    user.save()
    print(user)
    return user
Exemple #4
0
def create_user(lastName,
                firstName,
                login=None,
                password=None,
                phoneNumber=None,
                vkId=None,
                permissions=None):
    user = User(lastName=lastName, firstName=firstName)
    if login:
        user.login = login
    if password:
        user.password = password
    if phoneNumber:
        user.phoneNumber = phoneNumber
    if vkId:
        user.vkId = vkId
    if permissions:
        user.permissions = permissions
    user.save()
    print(user)
    return user
Exemple #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Exemple #6
0
from store.models import User
from store import db

db.create_all()
user = User(username='******', team='blue')
user.set_password('test')
db.session.add(user)
db.session.commit()