コード例 #1
0
ファイル: views.py プロジェクト: harshitcodes/spoken-website
def mdl_register(request):
    form = RegisterForm()
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            #Email exits
            try:
                user = MdlUser.objects.filter(
                    email=request.POST['email']).first().id
                messages.success(
                    request, "Email : " + request.POST['email'] +
                    " already registered on this website. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login"
                )
            except Exception, e:
                mdluser = MdlUser()
                mdluser.auth = 'manual'
                mdluser.institution = form.cleaned_data['college']
                mdluser.gender = form.cleaned_data['gender']
                mdluser.firstname = form.cleaned_data['firstname'].upper()
                mdluser.lastname = form.cleaned_data['lastname'].upper()
                mdluser.email = form.cleaned_data['email'].lower()
                mdluser.username = mdluser.email
                mdluser.password = encript_password(
                    form.cleaned_data['password'])
                mdluser.confirmed = 1
                mdluser.mnethostid = 1
                mdluser.save()
                mdluser = MdlUser.objects.get(email=mdluser.email)
                get_or_create_user(mdluser, form.cleaned_data['password'])
                messages.success(
                    request, "User " + form.cleaned_data['firstname'] + " " +
                    form.cleaned_data['lastname'] +
                    " Created!. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login"
                )
                return HttpResponseRedirect('/participant/register/')
コード例 #2
0
def forget_password(request):
    context = {}
    form = PasswordResetForm()
    if request.method == "POST":
        form = PasswordResetForm(request.POST)
        if form.is_valid():
            password_string = ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for _ in range(8))
            user = MdlUser.objects.filter(email=request.POST['email']).first()
            password_encript = encript_password(password_string)
            user.password = password_encript
            user.save()
            subject = "Spoken Tutorial Online Test password reset"
            to = [user.email]
            message = '''Hi {0},

Your account password at 'Spoken Tutorials Online Test Center' has been reset
and you have been issued with a new temporary password.

Your current login information is now:
   username: {1}
   password: {2}

Please go to this page to change your password:
   {3}

In most mail programs, this should appear as a blue link
which you can just click on.  If that doesn't work,
then cut and paste the address into the address
line at the top of your web browser window.

Cheers from the 'Spoken Tutorials Online Test Center' administrator,

Admin Spoken Tutorials
'''.format(user.firstname, user.username, password_string,
            'http://onlinetest.spoken-tutorial.org/login/change_password.php')

            # send email
            email = EmailMultiAlternatives(subject,
                                           message,
                                           '*****@*****.**',
                                           to=to,
                                           bcc=[],
                                           cc=[],
                                           headers={
                                               'Reply-To':
                                               '*****@*****.**',
                                               "Content-type":
                                               "text/html;charset=iso-8859-1"
                                           })

            result = email.send(fail_silently=False)
            messages.success(request,
                             "New password sent to your email " + user.email)
            return HttpResponseRedirect('/participant/login/')

    context = {'form': form}
    context.update(csrf(request))
    return render(request, 'mdl/templates/password_reset.html', context)
コード例 #3
0
ファイル: views.py プロジェクト: holyantony/spoken-website
def mdl_register(request):
    form = RegisterForm()
    if request.method == "POST":
        form = RegisterForm(request.POST)
        
        #Email exits
        try:
            user = MdlUser.objects.filter(email=request.POST['email']).first()
            if user:
                messages.success(request, "Email : "+request.POST['email']+" already registered on this website. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login")
        except Exception, e:
            #print e
            pass
            
        if form.is_valid():
            mdluser = MdlUser()
            mdluser.auth = 'manual'
            mdluser.institution = form.cleaned_data['college']
            mdluser.gender = form.cleaned_data['gender']
            mdluser.firstname = form.cleaned_data['firstname']
            mdluser.lastname = form.cleaned_data['lastname']
            mdluser.email = form.cleaned_data['email']
            mdluser.username = form.cleaned_data['username']
            mdluser.password = encript_password(form.cleaned_data['password'])
            mdluser.confirmed = 1
            mdluser.mnethostid = 1
            mdluser.save()
            messages.success(request, "User " + form.cleaned_data['firstname'] +" "+form.cleaned_data['lastname']+" Created!")
            return HttpResponseRedirect('/participant/register/')
コード例 #4
0
ファイル: views.py プロジェクト: harshitcodes/spoken-website
def changeMdlUserPass(email, password_string):
    try:
        user = MdlUser.objects.filter(email=email).first()
        password_encript = encript_password(password_string)
        user.password = password_encript
        user.save()
        return True
    except:
        return False
コード例 #5
0
ファイル: views.py プロジェクト: harshitcodes/spoken-website
def authenticate(email=None, password=None):
    try:
        password = encript_password(password)
        user = MdlUser.objects.filter(email=email, password=password).last()
        print user
        if user:
            return user
    except Exception, e:
        return None
コード例 #6
0
ファイル: views.py プロジェクト: harshitcodes/spoken-website
def changeMdlUserPass(email, password_string):
    try:
        user = MdlUser.objects.filter(email=email).first()
        password_encript = encript_password(password_string)
        user.password = password_encript
        user.save()
        return True
    except:
        return False
コード例 #7
0
ファイル: views.py プロジェクト: harshitcodes/spoken-website
def forget_password(request):
    context = {}
    form = PasswordResetForm()
    if request.method == "POST":
        form = PasswordResetForm(request.POST)
        if form.is_valid():
            password_string = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))
            user = MdlUser.objects.filter(email=request.POST['email']).first()
            password_encript = encript_password(password_string)
            user.password = password_encript
            user.save()
            # reset auth user password
            mdluser, flag, authuser = get_or_create_user(user)
            authuser.set_password(password_string)
            authuser.save()
            
            subject  = "Spoken Tutorial Online Test password reset"
            to = [user.email]
            message = '''Hi {0},

Your account password at 'Spoken Tutorials Online Test Center' has been reset
and you have been issued with a new temporary password.

Your current login information is now:
   username: {1}
   password: {2}

Please go to this page to change your password:
   {3}

In most mail programs, this should appear as a blue link
which you can just click on.  If that doesn't work,
then cut and paste the address into the address
line at the top of your web browser window.

Cheers from the 'Spoken Tutorials Online Test Center' administrator,

Admin Spoken Tutorials
'''.format(user.firstname, user.username, password_string, 'http://onlinetest.spoken-tutorial.org/login/change_password.php')

            # send email
            email = EmailMultiAlternatives(
                subject, message, '*****@*****.**',
                to = to, bcc = [], cc = [],
                headers={'Reply-To': '*****@*****.**', "Content-type":"text/html;charset=iso-8859-1"}
            )

            result = email.send(fail_silently=False)
            messages.success(request, "New password sent to your email "+user.email)
            return HttpResponseRedirect('/participant/login/')
            

    context = {
        'form': form
    }
    context.update(csrf(request))
    return render(request, 'mdl/templates/password_reset.html', context)
コード例 #8
0
ファイル: views.py プロジェクト: harshitcodes/spoken-website
def authenticate(email = None, password = None):
    try:
        password = encript_password(password)
        user = MdlUser.objects.filter(email=email, password=password).last()
        print user
        if user:
            return user
    except Exception, e:
        return None
コード例 #9
0
ファイル: forms.py プロジェクト: harshitcodes/spoken-website
 def clean_email(self):
     email = self.cleaned_data['email'].lower()
     error = 0
     try:
         user = MdlUser.objects.filter(email=email).first()
         user.id
         error = 1
         # check if user exists
         mdluser, flag, authuser = get_or_create_user(user)
         if flag:
             mdluser.password = encript_password(mdluser.firstname)
             mdluser.save()
             # send email along with password
     except Exception, e:
         return email
コード例 #10
0
 def clean_email(self):
     email = self.cleaned_data['email'].lower()
     error = 0
     try:
         user = MdlUser.objects.filter(email=email).first()
         user.id
         error = 1
         # check if user exists
         mdluser, flag, authuser = get_or_create_user(user)
         if flag:
         	mdluser.password = encript_password(mdluser.firstname)
         	mdluser.save()
         	# send email along with password
     except Exception, e:
         return email
コード例 #11
0
ファイル: views.py プロジェクト: holyantony/spoken-website
def authenticate(username = None, password = None):
    try:
        #print " i am in moodle auth"
        user = MdlUser.objects.get(username=username)
        #print user
        pwd = user.password
        p = encript_password(password)
        pwd_valid =  (pwd == p)
        #print pwd
        #print "------------"
        if user and pwd_valid:
            return user
    except Exception, e:
        #print e
        #print "except ---"
        return None
コード例 #12
0
def authenticate(username=None, password=None):
    try:
        #print " i am in moodle auth"
        user = MdlUser.objects.get(username=username)
        #print user
        pwd = user.password
        p = encript_password(password)
        pwd_valid = (pwd == p)
        #print pwd
        #print "------------"
        if user and pwd_valid:
            return user
    except Exception, e:
        #print e
        #print "except ---"
        return None