Exemple #1
0
        # 设置链接信息
        if True:
            douban = Link(user=new_user,type='douban')
            douban.name = me['name']
            douban.url = me['alt']
            douban.save()

        try:
            new_prfile.save()
        except Exception,e:
            new_user.delete()
            return HttpResponse('注册账号时服务器出现错误:%s' %str(e))
        else:
            #发送信号
            new_user_register.send(
                sender=new_prfile.user.__class__,
                profile = new_prfile
            )

        # 在微波上关注本站
        #try:
        #    api.create_friendship(user_id=1896993041)
        #except :
        #    pass

    # 登录当前的用户
    login_user = authenticate(username=username,password='******')
    auth_login(request,login_user)
    return HttpResponseRedirect('/')
Exemple #2
0
        new_prfile.city = me['loc_name']
        new_prfile.introduction = me['desc'][:200]

        # 设置链接信息
        if True:
            douban = Link(user=new_user, type='douban')
            douban.name = me['name']
            douban.url = me['alt']
            douban.save()

        try:
            new_prfile.save()
        except Exception, e:
            new_user.delete()
            return HttpResponse('注册账号时服务器出现错误:%s' % str(e))
        else:
            #发送信号
            new_user_register.send(sender=new_prfile.user.__class__,
                                   profile=new_prfile)

        # 在微波上关注本站
        #try:
        #    api.create_friendship(user_id=1896993041)
        #except :
        #    pass

    # 登录当前的用户
    login_user = authenticate(username=username, password='******')
    auth_login(request, login_user)
    return HttpResponseRedirect('/')
Exemple #3
0
def active(request, u_id, active_code):
    """
    用户账号激活处理
    """
    # XXX

    try:
        u_id = int(u_id)
        user = User.objects.get(id=u_id)
    except (User.DoesNotExist, ValueError):
        return HttpResponseRedirect('/')

    # 已经激活过
    if user.is_active:
        messages.success(request, '账号已经激活,请直接登录')
        return HttpResponseRedirect('/accounts/login/')

    # 验证激活码是否正确
    elif active_code == _get_active_code(user.email):
        user.is_active = True
        user.save()
        messages.success(request, '恭喜,账号激活成功!马上登录,体验一下吧。')

        # 发送信号
        new_user_register.send(sender=user.get_profile().__class__,
                               profile=user.get_profile())
        return HttpResponseRedirect('/accounts/login/')
    elif active_code == 'not_active':

        active_url = '%s/accounts/active/%d/%s/' % (
            DOMAIN, user.id, _get_active_code(user.username))
        subject = 'pythoner.net账号激活邮件'
        body = loader.render_to_string('account_active.email.html', {
            'user': user,
            'active_url': active_url
        })
        from_email = '*****@*****.**'
        to = [user.username]
        # 开启发送激活邮件线程
        send_email(subject, body, from_email, to)

        #  根据邮件地址找到信箱登录地址
        email_domains = {
            'qq.com': 'mail.qq.com',
            'foxmail.com': 'mail.qq.com',
            'gmail.com': 'www.gmail.com',
            '126.com': 'www.126.com',
            '163.com': 'www.163.com',
            '189.cn': 'www.189.cn',
            '263.net': 'www.263.net',
            'yeah.net': 'www.yeah.net',
            'sohu.com': 'mail.sohu.com',
            'tom.com': 'mail.tom.com',
            'hotmail.com': 'www.hotmail.com',
            'yahoo.com.cn': 'mail.cn.yahoo.com',
            'yahoo.cn': 'mail.cn.yahoo.com',
            '21cn.com': 'mail.21cn.com',
        }

        for key, value in email_domains.items():
            print user.username.count(key)
            if user.username.count(key) >= 1:
                email_domain = value
                break

        return render('account_active.html',
                      locals(),
                      context_instance=RequestContext(request))
    else:
        raise Http404()
Exemple #4
0
def active(request, u_id, active_code):
    """
    用户账号激活处理
    """
    # XXX

    try:
        u_id = int(u_id)
        user = User.objects.get(id=u_id)
    except (User.DoesNotExist, ValueError):
        return HttpResponseRedirect("/")

    # 已经激活过
    if user.is_active:
        messages.success(request, "账号已经激活,请直接登录")
        return HttpResponseRedirect("/accounts/login/")

    # 验证激活码是否正确
    elif active_code == _get_active_code(user.email):
        user.is_active = True
        user.save()
        messages.success(request, "恭喜,账号激活成功!马上登录,体验一下吧。")

        # 发送信号
        new_user_register.send(sender=user.get_profile().__class__, profile=user.get_profile())
        return HttpResponseRedirect("/accounts/login/")
    elif active_code == "not_active":

        active_url = "%s/accounts/active/%d/%s/" % (DOMAIN, user.id, _get_active_code(user.username))
        subject = "Python开发者社区-账号激活邮件"
        body = loader.render_to_string("account_active.email.html", {"user": user, "active_url": active_url})
        from_email = "*****@*****.**"
        to = [user.username]
        # 开启发送激活邮件线程
        send_email(subject, body, from_email, to)

        #  根据邮件地址找到信箱登录地址
        email_domains = {
            "qq.com": "mail.qq.com",
            "foxmail.com": "mail.qq.com",
            "gmail.com": "www.gmail.com",
            "126.com": "www.126.com",
            "163.com": "www.163.com",
            "189.cn": "www.189.cn",
            "263.net": "www.263.net",
            "yeah.net": "www.yeah.net",
            "sohu.com": "mail.sohu.com",
            "tom.com": "mail.tom.com",
            "hotmail.com": "www.hotmail.com",
            "yahoo.com.cn": "mail.cn.yahoo.com",
            "yahoo.cn": "mail.cn.yahoo.com",
            "21cn.com": "mail.21cn.com",
        }

        for key, value in email_domains.items():
            print user.username.count(key)
            if user.username.count(key) >= 1:
                email_domain = value
                break

        return render("account_active.html", locals(), context_instance=RequestContext(request))
    else:
        raise Http404()
Exemple #5
0
def active(request,u_id,active_code):
    """
    用户账号激活处理
    """
    # XXX

    try:
        u_id = int(u_id)
        user = User.objects.get(id=u_id)
    except (User.DoesNotExist,ValueError):
        return HttpResponseRedirect('/')

    # 已经激活过
    if user.is_active:
        messages.success(request,'账号已经激活,请直接登录')
        return HttpResponseRedirect('/accounts/login/')

    # 验证激活码是否正确
    elif active_code == _get_active_code(user.email):
        user.is_active = True
        user.save()
        messages.success(request,'恭喜,账号激活成功!马上登录,体验一下吧。')

        # 发送信号
        new_user_register.send(
            sender=user.get_profile().__class__,
            profile = user.get_profile()
        )
        return HttpResponseRedirect('/accounts/login/')
    elif active_code == 'not_active':

        active_url = '%s/accounts/active/%d/%s/' %(DOMAIN,user.id,_get_active_code(user.username))
        subject = 'Python开发者社区-账号激活邮件'
        body = loader.render_to_string('account_active.email.html',{'user':user,'active_url':active_url})
        from_email = '*****@*****.**'
        to = [user.username]
        # 开启发送激活邮件线程
        send_email(subject,body,from_email,to)

        #  根据邮件地址找到信箱登录地址
        email_domains = {
            'qq.com':'mail.qq.com',
            'foxmail.com':'mail.qq.com',
            'gmail.com':'www.gmail.com',
            '126.com':'www.126.com',
            '163.com':'www.163.com',
            '189.cn':'www.189.cn',
            '263.net':'www.263.net',
            'yeah.net':'www.yeah.net',
            'sohu.com':'mail.sohu.com',
            'tom.com':'mail.tom.com',
            'hotmail.com':'www.hotmail.com',
            'yahoo.com.cn':'mail.cn.yahoo.com',
            'yahoo.cn':'mail.cn.yahoo.com',
            '21cn.com':'mail.21cn.com',
        }

        for key,value in email_domains.items():
            print user.username.count(key)
            if user.username.count(key) >= 1:
                email_domain = value
                break

        return render('account_active.html',locals(),context_instance=RequestContext(request))
    else:
        raise Http404()