Ejemplo n.º 1
0
    def send_forget_password_email(self, email):
        '''
        @note: 发送密码找回邮件
        '''
        if not email:
            return 99800, dict_err.get(99800)

        user = self.get_user_by_email(email)
        if not user:
            return 10111, dict_err.get(10111)
        cache_obj = cache.Cache()
        key = u'forget_password_email_code_%s' % email
        code = cache_obj.get(key)
        if not code:
            code = utils.uuid_without_dash()
            cache_obj.set(key, code, time_out=1800)
            cache_obj.set(code, user, time_out=1800)

        if not cache_obj.get_time_is_locked(key, 60):
            context = {
                'reset_url':
                '%s/reset_password?code=%s' % (settings.MAIN_DOMAIN, code),
            }
            async_send_email(
                email, u'智选找回密码',
                utils.render_email_template('email/reset_password.html',
                                            context), 'html')
        return 0, dict_err.get(0)
Ejemplo n.º 2
0
def main():
    from www.tasks import async_send_email_worker
    from common import utils
    from www.kaihu.models import CustomerManager
    from www.account.interface import UserBase

    count = 0
    for cm in CustomerManager.objects.filter(state=True):
        user = UserBase().get_user_by_id(cm.user_id)
        if "@a.com" in user.email:
            continue
        print user.email

        print count
        count += 1
        if count < 43:
            continue

        context = dict(user=user)
        try:
            async_send_email_worker(
                user.email, u'智选双十一活动,一场属于证券客户经理的狂欢',
                utils.render_email_template('email/ad/11_email.html', context),
                'html')
        except Exception, e:
            print e
Ejemplo n.º 3
0
def main():
    import time
    import datetime
    from django.conf import settings
    from common import utils
    from www.weixin.interface import WexinBase
    from www.tasks import async_send_email
    from pprint import pprint

    wb = WexinBase()
    app_key = "cheka_test"
    to_user = '******'

    app_key = "cheka"
    to_user = '******'
    content = (u'古人云:鸟随鸾凤飞腾远,人伴贤良品质高。\n')

    # print wb.send_msg_to_weixin(content, to_user, app_key)

    context = {
        'reset_url':
        '%s/reset_password?code=%s' % (settings.MAIN_DOMAIN, "123"),
    }
    print async_send_email(
        "*****@*****.**", u'来自车咖',
        utils.render_email_template('email/reset_password.html', context),
        'html')
Ejemplo n.º 4
0
    def create_invite(self, from_user_id, to_user_id, question_id):
        try:
            from www.question.interface import QuestionBase

            ub = UserBase()
            try:
                from_user = ub.get_user_by_id(from_user_id)
                to_user = ub.get_user_by_id(to_user_id)
                question = QuestionBase().get_question_by_id(question_id)

                assert from_user and to_user and question
            except:
                transaction.rollback(using=DEFAULT_DB)
                return 99800, dict_err.get(99800)

            if from_user_id == to_user_id:
                transaction.rollback(using=DEFAULT_DB)
                return 40100, dict_err.get(40100)

            # 同一个问题最多邀请6个人
            if InviteAnswerIndex.objects.filter(from_user_id=from_user_id, question_id=question_id).count() >= 6:
                transaction.rollback(using=DEFAULT_DB)
                return 40101, dict_err.get(40101)

            # 重复邀请给出提示
            if InviteAnswerIndex.objects.filter(from_user_id=from_user_id, to_user_id=to_user_id, question_id=question_id):
                transaction.rollback(using=DEFAULT_DB)
                return 40102, dict_err.get(40102)

            try:
                ia = InviteAnswer.objects.create(from_user_ids=json.dumps([from_user_id, ]), to_user_id=to_user_id, question_id=question_id)
                need_update_unread_count = True
            except:
                ia = InviteAnswer.objects.get(to_user_id=to_user_id, question_id=question_id)
                from_user_ids = json.loads(ia.from_user_ids)
                if from_user_id not in from_user_ids:
                    from_user_ids.append(from_user_id)
                ia.from_user_ids = json.dumps(from_user_ids)
                ia.save()

                need_update_unread_count = True if ia.is_read else False

            # 建立索引
            InviteAnswerIndex.objects.create(from_user_id=from_user_id, to_user_id=to_user_id, question_id=question_id)

            # 更新未读消息,新邀请或者邀请已读才更新未读数
            if need_update_unread_count:
                UnreadCountBase().update_unread_count(to_user_id, code='invite_answer')

            # 发送提醒邮件
            context = dict(user=from_user, question=question)
            async_send_email(to_user.email, u'%s 在智选邀请你回答问题' % (from_user.nick, ), utils.render_email_template('email/invite.html', context), 'html')

            transaction.commit(using=DEFAULT_DB)
            return 0, dict_err.get(0)
        except Exception, e:
            debug.get_debug_detail(e)
            transaction.rollback(using=DEFAULT_DB)
            return 99900, dict_err.get(99900)
Ejemplo n.º 5
0
    def add_system_message(self, user_id, content, source=0, send_email=False):
        user = UserBase().get_user_by_id(user_id)
        if not user:
            return
        notice = Notice.objects.create(user_id=user_id, content=content, source=source)
        UnreadCountBase().update_unread_count(user_id, code='system_message')

        if send_email:
            # 发送提醒邮件
            context = dict(user=user, content=content)
            async_send_email(user.email, u'智选系统通知', utils.render_email_template('email/common_msg.html', context), 'html')

        return notice
Ejemplo n.º 6
0
def send_weekly_email():
    questions = get_all_important_question()
    if questions:
        context = dict(questions=questions)
        for user in User.objects.filter(state__gt=0):
            email = user.email
            context.update(dict(email=email))
            async_send_email(email, u'智选每周精选', utils.render_email_template('email/important.html', context), 'html')

        # email = ["*****@*****.**", "*****@*****.**", "*****@*****.**"]
        # async_send_email(email, u'智选每周精选', utils.render_email_template('email/important.html', context), 'html')

    print 'ok'
Ejemplo n.º 7
0
    def send_confirm_email(self, user):
        '''
        @note: 发送验证邮件
        '''
        cache_obj = cache.Cache()
        key = u'confirm_email_code_%s' % user.id
        code = cache_obj.get(key)
        if not code:
            code = utils.uuid_without_dash()
            cache_obj.set(key, code, time_out=1800)

        if not cache_obj.get_time_is_locked(key, 60):
            context = {'verify_url': '%s/account/user_settings/verify_email?code=%s' % (settings.MAIN_DOMAIN, code), }
            async_send_email(user.email, u'且行户外邮箱验证', utils.render_email_template('email/verify_email.html', context), 'html')
Ejemplo n.º 8
0
def send_weekly_email():
    questions = get_all_important_question()
    if questions:
        context = dict(questions=questions)
        for user in User.objects.filter(state__gt=0):
            email = user.email
            context.update(dict(email=email))
            async_send_email(
                email, u'智选每周精选',
                utils.render_email_template('email/important.html', context),
                'html')

        # email = ["*****@*****.**", "*****@*****.**", "*****@*****.**"]
        # async_send_email(email, u'智选每周精选', utils.render_email_template('email/important.html', context), 'html')

    print 'ok'
Ejemplo n.º 9
0
def main():
    import datetime
    from www.tasks import async_send_email_worker
    from common import utils
    from www.account.models import User

    count = 0
    for user in User.objects.filter(state__gt=0):
        if "@a.com" in user.email:
            continue
        print user.email

        print count
        count += 1

        context = dict(now_date=datetime.datetime.now().date(), email=user.email)
        try:
            async_send_email_worker(user.email, u'财经微头条,你获取财经资讯的最佳选择', utils.render_email_template('email/ad/weitoutiao_email.html', context), 'html')
        except Exception, e:
            print e
Ejemplo n.º 10
0
def main():
    import time
    import datetime
    from django.conf import settings
    from common import utils
    from www.weixin.interface import WexinBase
    from www.tasks import async_send_email
    from pprint import pprint

    wb = WexinBase()
    app_key = "cheka_test"
    to_user = '******'

    app_key = "cheka"
    to_user = '******'
    content = (u'古人云:鸟随鸾凤飞腾远,人伴贤良品质高。\n')

    # print wb.send_msg_to_weixin(content, to_user, app_key)

    context = {'reset_url': '%s/reset_password?code=%s' % (settings.MAIN_DOMAIN, "123"), }
    print async_send_email("*****@*****.**", u'来自车咖', utils.render_email_template('email/reset_password.html', context), 'html')
Ejemplo n.º 11
0
    def send_forget_password_email(self, email):
        '''
        @note: 发送密码找回邮件
        '''
        if not email:
            return 99800, dict_err.get(99800)

        user = self.get_user_by_email(email)
        if not user:
            return 10111, dict_err.get(10111)
        cache_obj = cache.Cache()
        key = u'forget_password_email_code_%s' % email
        code = cache_obj.get(key)
        if not code:
            code = utils.uuid_without_dash()
            cache_obj.set(key, code, time_out=1800)
            cache_obj.set(code, user, time_out=1800)

        if not cache_obj.get_time_is_locked(key, 60):
            context = {'reset_url': '%s/reset_password?code=%s' % (settings.MAIN_DOMAIN, code), }
            async_send_email(email, u'且行户外找回密码', utils.render_email_template('email/reset_password.html', context), 'html')
        return 0, dict_err.get(0)
Ejemplo n.º 12
0
def main():
    from www.tasks import async_send_email_worker
    from common import utils
    from www.kaihu.models import CustomerManager
    from www.account.interface import UserBase

    count = 0
    for cm in CustomerManager.objects.filter(state=True):
        user = UserBase().get_user_by_id(cm.user_id)
        if "@a.com" in user.email:
            continue
        print user.email

        print count
        count += 1
        if count < 43:
            continue

        context = dict(user=user)
        try:
            async_send_email_worker(user.email, u'智选双十一活动,一场属于证券客户经理的狂欢', utils.render_email_template('email/ad/11_email.html', context), 'html')
        except Exception, e:
            print e
Ejemplo n.º 13
0
def main():
    import datetime
    from www.tasks import async_send_email_worker
    from common import utils
    from www.account.models import User

    count = 0
    for user in User.objects.filter(state__gt=0):
        if "@a.com" in user.email:
            continue
        print user.email

        print count
        count += 1

        context = dict(now_date=datetime.datetime.now().date(),
                       email=user.email)
        try:
            async_send_email_worker(
                user.email, u'财经微头条,你获取财经资讯的最佳选择',
                utils.render_email_template('email/ad/weitoutiao_email.html',
                                            context), 'html')
        except Exception, e:
            print e
Ejemplo n.º 14
0
    def create_answer(self, question, from_user_id, content, ip=None):
        try:
            content = utils.filter_script(content)
            if not all((question, from_user_id, content)):
                transaction.rollback(using=QUESTION_DB)
                return 99800, dict_err.get(99800)

            errcode, errmsg = QuestionBase().validate_content(content)
            if not errcode == 0:
                transaction.rollback(using=QUESTION_DB)
                return errcode, errmsg

            to_user_id = question.user_id
            answer = Answer.objects.create(from_user_id=from_user_id,
                                           to_user_id=to_user_id,
                                           content=content,
                                           question=question,
                                           ip=ip)

            from_user = UserBase().get_user_by_id(from_user_id)
            # 添加at信息
            if content.find('@') != -1:
                at_usernicks = utils.select_at(content)
                for nick in at_usernicks:
                    at_user = UserBase().get_user_by_nick(nick)
                    if at_user:
                        # 自己@自己的关系不进行存储
                        if at_user.id != from_user_id:
                            AtAnswer.objects.create(answer=answer,
                                                    user_id=at_user.id)
                            if at_user.id != to_user_id:
                                # 更新@未读消息数
                                UnreadCountBase().update_unread_count(
                                    at_user.id, code='at_answer')

                                # 发送提醒邮件
                                context = dict(user=from_user, answer=answer)
                                async_send_email(
                                    at_user.email,
                                    u'%s 在智选回答中@了你' % (from_user.nick, ),
                                    utils.render_email_template(
                                        'email/at.html', context), 'html')

            # 更新未读消息
            if from_user_id != to_user_id:
                UnreadCountBase().update_unread_count(to_user_id,
                                                      code='received_answer')

                # 发送提醒邮件
                to_user = UserBase().get_user_by_id(to_user_id)
                context = dict(user=from_user, answer=answer)
                async_send_email(
                    to_user.email, u'%s 在智选回答了你的提问' % (from_user.nick, ),
                    utils.render_email_template('email/answer.html', context),
                    'html')

            # 更新用户回答统计总数
            UserCountBase().update_user_count(user_id=from_user_id,
                                              code='user_answer_count')

            # 更新回答数冗余信息
            question.answer_count += 1
            question.last_answer_time = datetime.datetime.now()
            question.save()

            # 发送feed
            if not question.is_silence:
                FeedBase().create_feed(from_user_id,
                                       feed_type=3,
                                       obj_id=answer.id)

            # 更新summary
            QuestionBase().get_question_summary_by_id(question,
                                                      must_update_cache=True)

            transaction.commit(using=QUESTION_DB)
            return 0, answer
        except Exception, e:
            debug.get_debug_detail(e)
            transaction.rollback(using=QUESTION_DB)
            return 99900, dict_err.get(99900)