コード例 #1
0
ファイル: views.py プロジェクト: geonition/django_auth
def new_password(request):
    """
    This function sends new password to the given email address.

    Returns:
        200 if successful
        400 if email address is not confirmed
        404 if email address is not found

    """

    if(request.method == "POST"):
        try:
            request_json = json.loads(request.body)
        except ValueError:
            return HttpResponseBadRequest("The post request was not valid JSON")
        except IndexError:
            return HttpResponseBadRequest("POST data was empty so no "
                                          "new_password value could be "
                                          "retrieved from it")

        email = request_json['email']
        current_user = User.objects.filter(email=email)[0]

        um = UserManager()
        password = um.make_random_password()

        current_site = Site.objects.get_current()
        context = {
            "current_user": current_user,
            "password": password,
            "current_site": current_site
        }
        subject = render_to_string(
            "email_templates/new_password_email_subject.txt", context)
        # remove superfluous line breaks
        subject = "".join(subject.splitlines())
        message = render_to_string(
            "email_templates/new_password_email_content.txt", context)


        try:
            send_mail(subject,
                        message,
                        '*****@*****.**',
                        [current_user.email])

            current_user.set_password(password)
            current_user.save()

            return HttpResponse(u"New password was sent")

        except BadHeaderError:

            return HttpResponseBadRequest(u'Invalid header found.')


    return HttpResponseBadRequest("This URL only accepts POST requests")
コード例 #2
0
ファイル: models.py プロジェクト: zanfranceschi/colabre
	def retrieve_access(cls, username_or_email):
		profiles = UserProfile.objects.filter(Q(user__username=username_or_email) | Q(user__email=username_or_email)).exclude(is_from_oauth=True)
		for user in [profile.user for profile in profiles]:
			um = UserManager()
			new_password = um.make_random_password(6, user.username)
			user.set_password(new_password)
			user.save()
			UserNotification.getNotification().notify_password_change(user, new_password)
		return len(profiles) > 0
コード例 #3
0
ファイル: h2lib.py プロジェクト: jcebXD/How2
def resend_password(user):
    um = UserManager()
    password=um.make_random_password(length=10,allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    user.set_password(str(password))
    user.save()
    subject='Tu nuevo password'
    message='Hola '+user.username+', Tu nuevo password es '+password
    recipient=[user.email]
    send_mail(subject, message, '*****@*****.**', recipient, fail_silently=False)
    print message
コード例 #4
0
def activate_user_and_create_password(user):
    studmail = user.username + "@stud.ntnu.no"
    if not (user.email):
        user.email = studmail

    user_manager = UserManager()
    password = user_manager.make_random_password()
    user.set_password(password)
    user.is_active = True
    user.save()
    return password
コード例 #5
0
ファイル: wych.py プロジェクト: wrabbit/skibi
def edytuj_rodzica(request,klasa_id,rod_id,klucz,r_id):
    if not request.user.is_authenticated():return HttpResponseRedirect('/')
    #model = slownik[klucz]
    try:
            manipulator = User.ChangeManipulator(rod_id)
    except User.DoesNotExist:
            raise Http404
    rekord = manipulator.original_object
    x = UserManager()
    pas = x.make_random_password()
    from django.contrib.auth.models import get_hexdigest
    #passs = get_hexdigest('sha1', '', pas)
    if request.POST:
            new_data = request.POST.copy()
            if new_data['password']=='':new_data['password']=rekord.password
            else:
                    u = User()
                    new_data['password'] = u.set_password(new_data['password'])
                    
            new_data['groups']=4
            
            errors = manipulator.get_validation_errors(new_data)
            if not errors:
                    
                    manipulator.do_html2python(new_data)
                    manipulator.save(new_data)
                    return HttpResponseRedirect('/'+klasa_id+ '/Lista uczniow/')           
    else:
            errors = {}
            new_data = rekord.__dict__
            

    form = oldforms.FormWrapper(manipulator, new_data, errors)
    u = Uczniowie_tmp.objects.get(id=r_id)
    full_name = u.get_full_name()
    return render_to_response('forms_wych.html',
    {klucz: form,'rekord': rekord,'tytul': 'Edycja','header':'Edycja ucznia','del':'yes','rod_id':rod_id,'dane_ucznia':full_name},
                              context_instance=RequestContext(request))
コード例 #6
0
ファイル: models.py プロジェクト: matsitka/django-goose
 def randomString():
    um = UserManager()
    return um.make_random_password(length=10)
コード例 #7
0
def randomString():
    um = UserManager()
    return (um.make_random_password(length=25))
コード例 #8
0
ファイル: views.py プロジェクト: geonition/softgis-api
   except ValueError, err:
       logger.error("Error at new_password request. Details: %s"  % str(err.args))
       return HttpResponseBadRequest("JSON error: " + str(err.args))
   except IndexError:
       return HttpResponseBadRequest(_("POST data was empty so no new_password value could be retrieven from it"))
   
   email = request_json['email']
   try:
       current_user = User.objects.get(email=email)
   except User.DoesNotExist:
       logger.warning("The user could not be found or the email address hasn't been confirmed")
       return HttpResponseBadRequest(_(u"The user could not be found or the email address hasn't been confirmed")) 
   
  
   um = UserManager()
   password = um.make_random_password(length=10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
   current_site = Site.objects.get_current()     
   context = {
       "current_user": current_user,
       "password": password,
       "current_site": current_site
   }
   subject = render_to_string(
       "email_templates/new_password_email_subject.txt", context)
   # remove superfluous line breaks
   subject = "".join(subject.splitlines())
   message = render_to_string(
       "email_templates/new_password_email_content.txt", context)
   
 
   try: