예제 #1
0
def change_username(request):
    can_change = request.user.getUserInfo().can_change_username
    if request.method.lower() == 'post':
        new_username = request.POST['new_username']
        try:
            user_services.change_username(request.user, new_username)
            messages.info(request, 'Your username has been changed')
        except FSException as e:
            messages.error(request, e.message)
    return render_to_response('core2/change_username.html',
                              {'can_change': can_change},
                              context_instance=RequestContext(request))
    def test_change_username(self):
        user = test_data.create_dummy_sponsor()

        change_ok = user_services.change_username(user, 'oreiudo')
        user = User.objects.get(pk=user.id)

        self.assertTrue(change_ok)
        self.assertEqual('oreiudo', user.username)

        user2 = test_data.create_dummy_sponsor()
        change_ok = user_services.change_username(user2, 'oreiudo')

        self.assertFalse(change_ok)
        self.assertNotEqual('oreiudo', user2.username)
def change_username(request):
    can_change = request.user.getUserInfo().can_change_username
    if request.method.lower() == 'post':
        new_username = request.POST['new_username']
        try:
            user_services.change_username(request.user, new_username)
            messages.info(request, 'Your username has been changed')
        except FSException as e:
            messages.error(request, e.message)
    return render_to_response(
        'core2/change_username.html',
        {'can_change': can_change},
        context_instance=RequestContext(request)
    )
    def test_change_username(self):
        user = test_data.create_dummy_sponsor()

        user_services.change_username(user, 'oreiudo')
        user = User.objects.get(pk=user.id)
        self.assertEqual('oreiudo', user.username)

        user2 = test_data.create_dummy_sponsor()
        deupau = False
        try:
            user_services.change_username(user2, 'oreiudo')
        except FSException as e:
            deupau = True
            self.assertTrue('already taken' in e.message)
        self.assertTrue(deupau)
        user2 = User.objects.get(pk=user2.id)
        self.assertNotEqual('oreiudo', user2.username)
def change_username(request):
    can_change = request.user.getUserInfo().can_change_username
    if request.method.lower() == 'post':
        if can_change:
            old_username = request.user.username
            new_username = request.POST['new_username']
            change_ok = user_services.change_username(request.user, new_username)
            if change_ok:
                messages.info(request, 'Your username has been changed')
                can_change = False
                subject = 'user %s changed username %s --> %s' % (request.user.id, old_username, new_username)
                body = '<a href="http://freedomsponsors.org/user/%s">%s</a>' % (request.user.id, new_username)
                mail_services.notify_admin(subject, body)
            else:
                messages.error(request, 'Sorry, that username is already taken')
        else:
            messages.warning(request, 'You cannot change your username anymore')
    return render_to_response(
        'core2/change_username.html',
        {'can_change': can_change},
        context_instance=RequestContext(request)
    )