Exemplo n.º 1
0
def forgetPassword(request, *args, **kwargs):
    """Forget password page"""
    initParam = {}
    if request.method == "POST":
        flag = False
        username = request.POST.get('username')
        if '@' in username:
            users = models.User.objects.filter(email=username)
            if users:
                type = 1
                flag = True
        else:
            users = models.User.objects.filter(username=username)
            if users:
                type = 2
                flag = True
        if flag:
            user = users[0]
            #Send the email to user
            notificationViews.sendResetPasswordEmail(request, type=type, user=user)
            email = common.hiddenEmail(user.email)
            initParam['msg'] = _('The password reset link has been sent to %(param)s. Please check your email, click attached link to change your password ASAP.') % {'param': email}
        else:
            initParam['error_msg'] = _('%(param)s do not exist.') % {'param': username}

    return render_to_response("usersetting/forget_password.html", initParam, context_instance=RequestContext(request))
Exemplo n.º 2
0
def securitySettingEmailUpdate(request, *args, **kwargs):
    initParam = {}
    user = get_object_or_404(models.User, pk=request.user.id, username=request.user.username)
    initParam['email'] = common.hiddenEmail(user.email)
    #Send the security verification email
    notificationViews.sendSecurityVerificationEmail(request, user=user)
    return render_to_response("usersetting/security_setting_email_update.html", initParam, context_instance=RequestContext(request))
Exemplo n.º 3
0
def registerActive(request, *args, **kwargs):
    """Send the active email to register."""
    initParam = {}
    if kwargs.get('username') and kwargs.get('pk'):
        user = get_object_or_404(models.User, pk=kwargs.get('pk'), username=kwargs.get('username'))
        initParam['email'] = common.hiddenEmail(user.email)
        #Send the register active email
        notificationViews.sendRegisterActiveEmail(request, user=user)
    return render_to_response("usersetting/register_active.html", initParam, context_instance=RequestContext(request))
Exemplo n.º 4
0
def securitySettingEmailUpdate(request, *args, **kwargs):
    initParam = {}
    user = get_object_or_404(models.User,
                             pk=request.user.id,
                             username=request.user.username)
    initParam['email'] = common.hiddenEmail(user.email)
    #Send the security verification email
    notificationViews.sendSecurityVerificationEmail(request, user=user)
    return render_to_response("usersetting/security_setting_email_update.html",
                              initParam,
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
def registerActive(request, *args, **kwargs):
    """Send the active email to register."""
    initParam = {}
    if kwargs.get('username') and kwargs.get('pk'):
        user = get_object_or_404(models.User,
                                 pk=kwargs.get('pk'),
                                 username=kwargs.get('username'))
        initParam['email'] = common.hiddenEmail(user.email)
        #Send the register active email
        notificationViews.sendRegisterActiveEmail(request, user=user)
    return render_to_response("usersetting/register_active.html",
                              initParam,
                              context_instance=RequestContext(request))
Exemplo n.º 6
0
def securitySetting(request, *args, **kwargs):
    """security setting include email, phone"""
    initParam = {}
    user = get_object_or_404(models.User, pk=request.user.id, username=request.user.username)
    securitySettings = user.securityverification_set.all()
    for securitySetting in securitySettings:
        if securitySetting.vtype == 1:
            securitySetting.value = common.hiddenEmail(securitySetting.value)
            initParam['email_info'] = securitySetting
        if securitySetting.vtype == 2:
            securitySetting.value = common.hiddenPhone(securitySetting.value)
            initParam['phone_info'] = securitySetting
    return render_to_response("usersetting/security_setting.html", initParam, context_instance=RequestContext(request))
Exemplo n.º 7
0
 def run(self):
     try:
         #subject or message can not be filled.
         if isinstance(self.recipient_list, list) and len(self.recipient_list) > 0:
             send_mail(self.subject, self.message, self.from_email, self.recipient_list, self.fail_silently)
             email_str = ''
             for email in self.recipient_list:
                 email_str += common.hiddenEmail(email) + ' '
             log.info('Send email successfully. [' + email_str + '] ' + self.subject)
         else:
             log.error('Email recipient_list is not correct.')
     except BadHeaderError as e:
         log.error('Send email failed from BadHeaderError. ' + str(e))
     except Exception as e:
         log.error('Send email failed. ' + str(e))
Exemplo n.º 8
0
def securitySetting(request, *args, **kwargs):
    """security setting include email, phone"""
    initParam = {}
    user = get_object_or_404(models.User,
                             pk=request.user.id,
                             username=request.user.username)
    securitySettings = user.securityverification_set.all()
    for securitySetting in securitySettings:
        if securitySetting.vtype == 1:
            securitySetting.value = common.hiddenEmail(securitySetting.value)
            initParam['email_info'] = securitySetting
        if securitySetting.vtype == 2:
            securitySetting.value = common.hiddenPhone(securitySetting.value)
            initParam['phone_info'] = securitySetting
    return render_to_response("usersetting/security_setting.html",
                              initParam,
                              context_instance=RequestContext(request))
Exemplo n.º 9
0
 def run(self):
     try:
         #subject or message can not be filled.
         if isinstance(self.recipient_list,
                       list) and len(self.recipient_list) > 0:
             send_mail(self.subject, self.message, self.from_email,
                       self.recipient_list, self.fail_silently)
             email_str = ''
             for email in self.recipient_list:
                 email_str += common.hiddenEmail(email) + ' '
             log.info('Send email successfully. [' + email_str + '] ' +
                      self.subject)
         else:
             log.error('Email recipient_list is not correct.')
     except BadHeaderError as e:
         log.error('Send email failed from BadHeaderError. ' + str(e))
     except Exception as e:
         log.error('Send email failed. ' + str(e))
Exemplo n.º 10
0
def paymentAccount(request, *args, **kwargs):
    """payment account setting."""
    initParam = {}
    user = get_object_or_404(models.User,
                             pk=request.user.id,
                             username=request.user.username)

    if request.method == "POST":
        types = request.POST.getlist('gateway_type')
        accounts = request.POST.getlist('payment_account')
        if types and accounts and len(types) == len(accounts):
            for i in range(len(types)):
                gateway = get_object_or_404(paymentModels.Gateway, pk=types[i])
                acceptGateways = user.acceptgateway_set.filter(
                    type_id=types[i])
                if acceptGateways:
                    acceptGateway = acceptGateways[0]
                else:
                    acceptGateway = paymentModels.AcceptGateway()
                    acceptGateway.user = user
                    acceptGateway.type = gateway
                acceptGateway.value = accounts[i].strip()
                acceptGateway.is_active = True
                acceptGateway.is_default = True
                acceptGateway.save()
            initParam['account_msg'] = _('Payment account is updated.')
            #The parameter 'next' means the original URL.
            if request.POST.get('next'):
                return redirect(''.join(['/', request.POST.get('next')]))

    #Init payment account data in page.
    gateways_map = {}
    for gateway in paymentModels.Gateway.objects.filter(is_active=True):
        gateways_map[gateway] = None
    for acceptGateway in user.acceptgateway_set.all():
        acceptGateway.value = common.hiddenEmail(acceptGateway.value)
        gateways_map[acceptGateway.type] = acceptGateway
    initParam['gateways_map'] = gateways_map
    if kwargs.get('next'):
        initParam['next'] = kwargs.get('next')

    return render_to_response("usersetting/accept_payment.html",
                              initParam,
                              context_instance=RequestContext(request))
Exemplo n.º 11
0
def loginView(request, *args, **kwargs):
    initParam = {}
    user = authenticate(username=request.POST.get('username'),
                        password=request.POST.get('password'))
    redirect_to = request.POST.get('next', None)
    redirect_urls = (None, '', '/usersetting/', '/dashboard/')
    for url in redirect_urls:
        if redirect_to == url or (url and redirect_to.startswith(str(url))):
            redirect_to = '/'
            break
    if redirect_to.startswith('/bid/bid-create/'):
        paths = redirect_to.split('/')
        if len(paths) == 4:
            redirect_to = reverse('query:app_detail',
                                  kwargs={'pk': str(paths[3])})
        else:
            redirect_to = '/'

    if user:
        blackList = models.BlackList.objects.filter(user_id=user.id)
        if blackList:
            initParam['login_error'] = _(
                'Your account has been listed in blacklist!')
        elif user.is_active:
            login(request, user)
            #record user login info, such as IP.
            userLoginInfo = models.UserLoginInfo()
            userLoginInfo.user = user
            userLoginInfo.ip = common.getUserClientIP(request)
            userLoginInfo.save()
            log.info('%(name)s login.' % {'name': user.username})
            return redirect(redirect_to)
        else:
            initParam['login_error'] = _(
                '%(name)s is not active. Please active it by %(email)s.') % {
                    'name': user.username,
                    'email': common.hiddenEmail(user.email)
                }
    else:
        initParam['login_error'] = _('username or password is not correct.')
    initParam['user_name'] = request.POST.get('username')
    return render_to_response("usersetting/login.html",
                              initParam,
                              context_instance=RequestContext(request))
Exemplo n.º 12
0
def paymentAccount(request, *args, **kwargs):
    """payment account setting."""
    initParam = {}
    user = get_object_or_404(models.User, pk=request.user.id, username=request.user.username)

    if request.method == "POST":
        types = request.POST.getlist('gateway_type')
        accounts = request.POST.getlist('payment_account')
        if types and accounts and len(types) == len(accounts):
            for i in range(len(types)):
                gateway = get_object_or_404(paymentModels.Gateway, pk=types[i])
                acceptGateways = user.acceptgateway_set.filter(type_id=types[i])
                if acceptGateways:
                    acceptGateway = acceptGateways[0]
                else:
                    acceptGateway = paymentModels.AcceptGateway()
                    acceptGateway.user = user
                    acceptGateway.type = gateway
                acceptGateway.value = accounts[i].strip()
                acceptGateway.is_active = True
                acceptGateway.is_default = True
                acceptGateway.save()
            initParam['account_msg'] = _('Payment account is updated.')
            #The parameter 'next' means the original URL.
            if request.POST.get('next'):
                return redirect(''.join(['/', request.POST.get('next')]))

    #Init payment account data in page.
    gateways_map = {}
    for gateway in paymentModels.Gateway.objects.filter(is_active=True):
        gateways_map[gateway] = None
    for acceptGateway in user.acceptgateway_set.all():
        acceptGateway.value = common.hiddenEmail(acceptGateway.value)
        gateways_map[acceptGateway.type] = acceptGateway
    initParam['gateways_map'] = gateways_map
    if kwargs.get('next'):
        initParam['next'] = kwargs.get('next')

    return render_to_response("usersetting/accept_payment.html", initParam, context_instance=RequestContext(request))
Exemplo n.º 13
0
def forgetPassword(request, *args, **kwargs):
    """Forget password page"""
    initParam = {}
    if request.method == "POST":
        flag = False
        username = request.POST.get('username')
        if '@' in username:
            users = models.User.objects.filter(email=username)
            if users:
                type = 1
                flag = True
        else:
            users = models.User.objects.filter(username=username)
            if users:
                type = 2
                flag = True
        if flag:
            user = users[0]
            #Send the email to user
            notificationViews.sendResetPasswordEmail(request,
                                                     type=type,
                                                     user=user)
            email = common.hiddenEmail(user.email)
            initParam['msg'] = _(
                'The password reset link has been sent to %(param)s. Please check your email, click attached link to change your password ASAP.'
            ) % {
                'param': email
            }
        else:
            initParam['error_msg'] = _('%(param)s do not exist.') % {
                'param': username
            }

    return render_to_response("usersetting/forget_password.html",
                              initParam,
                              context_instance=RequestContext(request))
Exemplo n.º 14
0
def loginView(request, *args, **kwargs):
    initParam = {}
    user = authenticate(username=request.POST.get('username'), password=request.POST.get('password'))
    redirect_to = request.POST.get('next', None)
    redirect_urls = (None, '', '/usersetting/', '/dashboard/')
    for url in redirect_urls:
        if redirect_to == url or (url and redirect_to.startswith(str(url))):
            redirect_to = '/'
            break
    if redirect_to.startswith('/bid/bid-create/'):
        paths = redirect_to.split('/')
        if len(paths) == 4:
            redirect_to = reverse('query:app_detail', kwargs={'pk': str(paths[3])})
        else:
            redirect_to = '/'

    if user:
        blackList = models.BlackList.objects.filter(user_id=user.id)
        if blackList:
            initParam['login_error'] = _('Your account has been listed in blacklist!')
        elif user.is_active:
            login(request, user)
            #record user login info, such as IP.
            userLoginInfo = models.UserLoginInfo()
            userLoginInfo.user = user
            userLoginInfo.ip = common.getUserClientIP(request)
            userLoginInfo.save()
            log.info('%(name)s login.' % {'name': user.username})
            return redirect(redirect_to)
        else:
            initParam['login_error'] = _('%(name)s is not active. Please active it by %(email)s.') % {'name': user.username, 'email': common.hiddenEmail(user.email)}
    else:
        initParam['login_error'] = _('username or password is not correct.')
    initParam['user_name'] = request.POST.get('username')
    return render_to_response("usersetting/login.html", initParam, context_instance=RequestContext(request))