コード例 #1
0
def account_forgot_password(request):
    if request.user.is_authenticated():
        logout(request)

    form = ForgotPasswordForm()
    if request.method == 'POST':
        form = ForgotPasswordForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            user = User.objects.get(email=email)
            role_controller = RoleController(user)
            role = select_most_appropriate_user_role(role_controller)

            notification, created = Notification.objects.get_or_create(
                notification_type=Notification.RESET_PASSWORD,
                target_entity_id=role.entity.id,
                target_entity_type=role.entity_type)
            token = str(uuid4())
            link = '%s/users/account/reset_password?token=%s' % (
                settings.SPUDMART_BASE_URL, token)
            notification.extras = {'link': link, 'token': token}
            notification.save()
            CommunicationController.CommunicateWithEmail(
                [email], **{'notification': notification})

            return render_to_response(
                'spudderaccounts/pages/reset_password_link_sent.html',
                {'email': email})
    data = {'form': form}
    return render_to_response('spudderaccounts/pages/forgot_password.html',
                              data)
コード例 #2
0
def account_forgot_password(request):
    if request.user.is_authenticated():
        logout(request)

    form = ForgotPasswordForm()
    if request.method == 'POST':
        form = ForgotPasswordForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            user = User.objects.get(email=email)
            role_controller = RoleController(user)
            role = select_most_appropriate_user_role(role_controller)

            notification, created = Notification.objects.get_or_create(
                notification_type=Notification.RESET_PASSWORD,
                target_entity_id=role.entity.id,
                target_entity_type=role.entity_type
            )
            token = str(uuid4())
            link = '%s/users/account/reset_password?token=%s' % (settings.SPUDMART_BASE_URL, token)
            notification.extras = {'link': link, 'token': token}
            notification.save()
            CommunicationController.CommunicateWithEmail([email], **{'notification': notification})

            return render_to_response('spudderaccounts/pages/reset_password_link_sent.html', {'email': email})
    data = {'form': form}
    return render_to_response('spudderaccounts/pages/forgot_password.html', data)
コード例 #3
0
 def _add_current_role(self, request):
     current_role = None
     if request.user and request.user.is_authenticated():
         role_controller = RoleController(request.user)
         current_role = request.session.get('current_role', None)
         if not current_role:
             one_ane_only_role = select_most_appropriate_user_role(role_controller)
             if one_ane_only_role:
                 current_role = {
                     'entity_type': one_ane_only_role.entity_type,
                     'entity_id': one_ane_only_role.entity.id}
         if current_role:
             change_current_role(request, current_role['entity_type'], current_role['entity_id'])
             current_role = role_controller.role_by_entity_type_and_entity_id(
                 current_role['entity_type'],
                 current_role['entity_id'],
                 RoleBase.RoleWrapperByEntityType(current_role['entity_type']))
     request.current_role = current_role
コード例 #4
0
 def _add_current_role(self, request):
     current_role = None
     if request.user and request.user.is_authenticated():
         role_controller = RoleController(request.user)
         current_role = request.session.get('current_role', None)
         if not current_role:
             one_ane_only_role = select_most_appropriate_user_role(
                 role_controller)
             if one_ane_only_role:
                 current_role = {
                     'entity_type': one_ane_only_role.entity_type,
                     'entity_id': one_ane_only_role.entity.id
                 }
         if current_role:
             change_current_role(request, current_role['entity_type'],
                                 current_role['entity_id'])
             current_role = role_controller.role_by_entity_type_and_entity_id(
                 current_role['entity_type'], current_role['entity_id'],
                 RoleBase.RoleWrapperByEntityType(
                     current_role['entity_type']))
     request.current_role = current_role