Exemple #1
0
def signup(request):
    if request.method == "POST":
        user = UserModel(username=request.POST['username'],
                         name=request.POST.get('username'),
                         role='instructor')
        user.set_password(request.POST['password'])
        user.save()
        return HttpResponseRedirect('/')
    return render(request, 'registration/signup.html')
Exemple #2
0
def signup(request):
    if request.method == "POST":
        print request.POST
        user = UserModel(username=request.POST['username'],
                         last_name=request.POST.get('last_name'),
                         first_name=request.POST.get('first_name'))
        user.set_password(request.POST['password'])
        user.save()
    return render(request, 'registration/signup.html')
Exemple #3
0
 def handle(self, *args, **options):
     admin = UserModel(name='admin',
                       pinyin='admin',
                       phone='15116381393',
                       email='*****@*****.**',
                       gender=GENDER_MALE,
                       password=hashers.make_password('123456'),
                       character='A')
     admin.save()
     self.stdout.write(self.style.SUCCESS('添加Admin帐号成功'))
Exemple #4
0
 def mutate_and_get_payload(cls, root, info, **input):
     name = input.get('name')
     auth = input.get('auth_provider').get('email')
     email = auth.get('email')
     password = auth.get('password')
     if UserModel.objects.filter(email=email).exists():
         raise Exception('A user with that email address already exists!')
     user = UserModel(
         name=name,
         email=email,
         password=password,
     )
     user.save()
     return CreateUser(user=user)
Exemple #5
0
def register(request):
    request_form = RegisterForm(request.POST)
    if request_form.is_valid():
        post = request.POST
        user_name = post.get('user_name', '')
        pass_word1 = post.get('pass_word1', '')
        pass_word2 = post.get('pass_word2', '')
        if pass_word1 != pass_word2:
            return render(request, 'users/register.html')
        email = post.get('email', '')
        users = UserModel()
        users.username = user_name
        users.password = make_password(pass_word2)
        users.email = email
        users.save()
        return render(request, 'blog/index.html')
    else:
        return render(request, 'users/register.html')
def create_user(request):

    if request.method == "POST":
        body_unicode = request.body.decode("utf-8")
        print(body_unicode)
        body = json.loads(body_unicode)
        first_name = body["first_name"]
        last_name = body["last_name"]
        email = body["email"]
        phone_number = body["phone_number"]
        if body["is_manager"] == "False":
            is_manager = False
        else:
            is_manager = True
        str_password = body["password"]
        password = make_password(str_password)
        user = UserModel(
            first_name=first_name,
            last_name=last_name,
            phone_number=phone_number,
            is_manager=is_manager,
            email=email,
            password=password,
        )
        user.save()

        # users = UserModel.objects.get(phone_number =phone_number)
        # url = 'http://localhost:8000/api/token/'
        # data = {"username":phone_number,"password":str_password}
        # response = requests.post(url, data = data)
        # response_json = convert_bytes_array_to_json(response.content)
        # response_data = {"token" : response_json["token"]}
        response_data = {"status": "User Created"}
        return JsonResponse(response_data)

    else:
        response_data = {"status": "Get request not allowed."}
        return JsonResponse(response_data)
    def create(self, validated_data):
        user = UserModel(email=validated_data["email"])
        user.set_password(validated_data["password"])
        user.save()

        return user