Ejemplo n.º 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')
Ejemplo n.º 2
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
Ejemplo n.º 3
0
Archivo: auth.py Proyecto: Zubry/Sahara
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'})
Ejemplo n.º 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