Beispiel #1
0
def add_teacher_form(request):
    context = {
        'AddTeacherForm': TeacherSignupForm,
    }
    if request.method == 'GET':
        return render(request, 'Manager/Teacher Related/add_teacher_form.html',
                      context)
    else:
        email = request.POST.get("email")
        user_name = request.POST.get("username")
        password = randomPassword(10)
        html = f'Please use below autogenerated password to login with your email. Password is </br> <h1> { password} </h1>.'
        user = Account(email=email,
                       password=make_password(password),
                       is_teacher=True,
                       is_staff=True)
        user.save()
        EmailAuto(recipient_list=[
            email,
        ], html_message=html)
        teacher = Teacher(user=user, username=user_name)
        teacher.save()
        messages.success(request,
                         f"Teacher '{ user.email }' created successfully.  ")
        return redirect('manager_dashboard')
Beispiel #2
0
 def post(self, request):
     a = Account()
     a.accountName = str(request.POST["name"])
     a.accountEmail = str(request.POST["email"])
     a.accountTitle = str(request.POST["title"])
     a.accountHP = str(request.POST["phone"])
     a.accountAddress = str(request.POST["address"])
     a.save()
     b = list(Account.objects.all())  #objects.filter() cascade delete
     return render(request, "index.html", {"a": a, "b": b})
Beispiel #3
0
 def create(self, validated_data):
     account = Account(email=validated_data['email'],
                       account_type=validated_data['account_type'],
                       fullname=validated_data.get('fullname', None),
                       firstname=validated_data.get('firstname', None),
                       lastname=validated_data.get('lastname', None))
     account.set_unusable_password()
     account.set_social_id(validated_data.get('social_id', None))
     account.save()
     return account
Beispiel #4
0
 def create(self, validated_data):
     account = Account(email=validated_data['email'],
                       fullname=validated_data.get('fullname', None),
                       firstname=validated_data.get('firstname', None),
                       lastname=validated_data.get('lastname', None))
     password = validated_data['password']
     password2 = validated_data['password2']
     if password != password2:
         raise serializers.ValidationError(
             {'password': '******'})
     account.set_password(password)
     account.save()
     return account
Beispiel #5
0
    def save(self):
        account = Account(email=self.validated_data['email'],
                          username=self.validated_data['username'])

        password = self.validated_data['password']
        password2 = self.validated_data['password2']

        if password != password2:
            raise serializers.ValidationError(
                {'password': "******"})
        account.set_password(password)
        account.save()
        return account
Beispiel #6
0
def manager_studentview(request):
    if request.method == 'GET':
        return render(request,'manager/manager_studentview.html')
    else:
        email = request.POST.get('email')
        name = request.POST.get('name')
        contact = request.POST['contact']
        password = randomPassword()
        user = Account(email=email, password=make_password(password), is_teacher=False,is_manager=False,is_student=True)
        user.save()
        msg = f'{name}, your account is created successfully \n use the following credential to login \n email:{email} \n password:{password}'
        Mail(subject='Account created', message=msg,recipient_list=[email])
        student = Student(name=name, contact=contact, user_id=user.id)
        student.save()
        messages.add_message(request,messages.SUCCESS,'student Account is created successfully')
        return redirect('manager_view')
Beispiel #7
0
def OwnerAccountCreate(request):
    if request.method == 'GET':
        return render(request,'owner_register.html')
    else:
        email = request.POST.get('email')
        fname = request.POST.get('fname')
        lname = request.POST.get('lname')
        contact = request.POST['contact']
        address = request.POST['address']
        password = randomPassword()
        user = Account(email=email, first_name=fname,last_name=lname,password=make_password(password),is_owner=True,is_client=False)
        user.save()
        msg = f'{fname + lname}, your account is created successfully \n use the following credential to login \n email:{email} \n password:{password}'
        Mail(subject='Account created', message=msg, recipient_list=[email])
        owner = OwnerInfo(email=request.user.email,address=address,name=fname + lname, contact=contact, user_id=user.id)
        owner.save()
        messages.add_message(request,messages.SUCCESS,'owner Account is created successfully')
        return render(request,'signin.html')
Beispiel #8
0
def ClientAccountCreate(request):
    if request.method == 'GET':
        return render(request,'client_register.html')
    else:
        fname = request.POST['fname']
        lname = request.POST['lname']
        contact = request.POST['contact']
        address = request.POST.get('address')
        email = request.POST['email']
        no_of_person = request.POST['no_of_person']
        password = randomPassword()
        user = Account(email=email, first_name=fname, last_name=lname, password=make_password(password), is_owner=False,
                       is_client=True)
        user.save()
        msg = f'{fname + lname}, your account is created successfully \n use the following credential to login \n email:{email} \n password:{password}'
        Mail(subject='Account created', message=msg, recipient_list=[email])
        client = Client(name=fname+lname, contact=contact, address=address, email=email, no_of_person=no_of_person, user_id=user.id)
        client.save()
        messages.add_message(request,messages.SUCCESS,'client Account created successfully')
        return render(request, 'signin.html')
Beispiel #9
0
    def createAccount(self, command):

        # Check that the command has the correct number of arguments
        if len(command) != 4:
            return "Your command is missing arguments, please enter your command in the following format: " \
                   "createAccount username title email"

        # Check that the account trying to be created does not already exist
        if Account.objects.filter(userName=command[1]).exists():
            return "Account already exists"

        # Make sure the account is trying to be created with a UWM email address
        str = command[3].split('@', 1)
        if len(str) == 1:
            return "The email address you have entered in not valid.  " \
                   "Please make sure you are using a uwm email address in the correct format."
        if str[1] != "uwm.edu":
            return "The email address you have entered in not valid.  " \
                    "Please make sure you are using a uwm email address in the correct format."

        # If we get here the account is safe to be created.
        else:
            A = Account()
            A.userName = command[1]
            A.email = command[3]
            if command[2].lower() == "ta":
                A.title = 1
            elif command[2].lower() == "instructor":
                A.title = 2
            else:
                return "Invalid title, account not created"

            # Make a temporary password for the newly created user
            A.password = A.userName + "456"
            A.save()

            return "Account successfully created.  Temporary password is: " + A.userName + "456"