Example #1
0
 def POST(self):
     data = web.input()
     username = data.param
     if users.is_username_available(username):
         return "y"
     else:
         return "这个用户名太受欢迎已被注册了"
Example #2
0
 def POST(self):
     data = web.input()
     username = data.param
     if users.is_username_available(username):
         return "y"
     else:
         return "这个用户名太受欢迎已被注册了"
Example #3
0
    def POST(self, pid):
        data = web.input()
        uid = user.id
        aid = data.aid #note : 需要改成在后端通过pid得到aid,不能从前端传过来
        p = postModel.getPostByPostId(pid) #得到目标post

        reg_regchar = '@([a-zA-Z0-9][\w\-\.\_]+)'
        comment = data.postComment
        comment = htmlquote(comment).strip().replace("\r\n", "<br/>")
        usernames = re.findall(reg_regchar, comment)
        nicknames = []
        nickname_list = []
        mid_list = []

        # @提醒
        for i in xrange(len(usernames)):
            if not users.is_username_available(usernames[i]):
                nicknames += users.get_user_by_username(usernames[i]).nickname.replace(' ', '&nbsp;').split()
                comment = comment.replace('@'+ usernames[i], '@<a href="/member/'+ usernames[i] +'">' + nicknames[i] + '</a>')
                #得到@的用户id 以|分割组成字符串
                mid_list += str(users.get_user_by_username(usernames[i]).id).split()
                #去重
                mid_list = sorted(set(mid_list),key=mid_list.index)
                #以字符串形势保存@到的uid,以|分割
                # mention_id_list = '|'.join(mid_list)
            else:
                nicknames += usernames[i].split()
                comment = comment.replace('@'+ usernames[i], '@' + nicknames[i])

        # @提醒
        for mid in mid_list:
            if int(mid) !=  int(aid):
                notification.new_mention_notification(pid, p.nodeId, aid, uid,mid)
        
        print '=======notification send====='

        # 评论提醒 tp=1 表示是评论类型的提醒 同时判断是不是本人评论本人
        #这里很奇怪,不能直接判断aid 和 uid 是否相等,必须转成int
        if int(aid) != int(uid):

            notification.new_notification(aid, uid, pid, p.nodeId, tp=1)

            #如果开启了邮件提醒,给作者发送邮件
            author = users.get_user_by_id(aid)
            person = users.get_profile_by_user_id(aid)
            p = postModel.getPostByPostId(pid) #得到目标post
            if person.has_key('email_subscribe') and person.email_subscribe == 1 and author.email:
                email_templates.someone_comment_ur_post(user, author, p)
                print '=== email send =='

        postModel.add_post_comment(comment, uid, pid)
        #得到刚刚添加的comment的id,返回ajax给li添加id 供删除用
        last_comment = postModel.get_just_added_comment(uid, pid).id

        return '{"status": "y", "comment_id": "'+ str(last_comment) +'"}'
Example #4
0
#表单
login_form = form.Form(
    form.Textbox('email', form.notnull, vemail, description='邮箱:'),
    form.Password('password', form.notnull, description='密码:'),
    validators=[
        form.Validator(
            '邮箱地址或密码不正确',
            lambda i: users.is_correct_password(i.email, i.password))
    ])

register_form = form.Form(
    form.Textbox(
        'username',
        form.notnull,
        form.Validator('用户名已存在.', lambda x: users.is_username_available(x)),
        #form.Validator('请以字母开头,不超过15个字母、数字,保存后不可修改', #todo
        #lambda x: users.is_username_available(x)),
        description='用户名(以字母开头的2-16个字母、数字组合):'),
    form.Textbox('email',
                 form.notnull,
                 vemail,
                 form.Validator('邮箱已经存在.',
                                lambda x: users.is_email_available(x)),
                 description='邮箱:'),
    form.Password('password',
                  form.notnull,
                  form.Validator('密码不能少于6个字符.',
                                 lambda x: users.is_valid_password(x)),
                  description='密码:'),
    form.Textbox('nickname', form.notnull, description='昵称:'),
Example #5
0
    def POST(self, pid):
        data = web.input()
        uid = user.id
        aid = data.aid  #note : 需要改成在后端通过pid得到aid,不能从前端传过来
        p = postModel.getPostByPostId(pid)  #得到目标post

        reg_regchar = '@([a-zA-Z0-9][\w\-\.\_]+)'
        comment = data.postComment
        comment = htmlquote(comment).strip().replace("\r\n", "<br/>")
        usernames = re.findall(reg_regchar, comment)
        nicknames = []
        nickname_list = []
        mid_list = []

        # @提醒
        for i in xrange(len(usernames)):
            if not users.is_username_available(usernames[i]):
                nicknames += users.get_user_by_username(
                    usernames[i]).nickname.replace(' ', '&nbsp;').split()
                comment = comment.replace(
                    '@' + usernames[i], '@<a href="/member/' + usernames[i] +
                    '">' + nicknames[i] + '</a>')
                #得到@的用户id 以|分割组成字符串
                mid_list += str(users.get_user_by_username(
                    usernames[i]).id).split()
                #去重
                mid_list = sorted(set(mid_list), key=mid_list.index)
                #以字符串形势保存@到的uid,以|分割
                # mention_id_list = '|'.join(mid_list)
            else:
                nicknames += usernames[i].split()
                comment = comment.replace('@' + usernames[i],
                                          '@' + nicknames[i])

        # @提醒
        for mid in mid_list:
            if int(mid) != int(aid):
                notification.new_mention_notification(pid, p.nodeId, aid, uid,
                                                      mid)

        print '=======notification send====='

        # 评论提醒 tp=1 表示是评论类型的提醒 同时判断是不是本人评论本人
        #这里很奇怪,不能直接判断aid 和 uid 是否相等,必须转成int
        if int(aid) != int(uid):

            notification.new_notification(aid, uid, pid, p.nodeId, tp=1)

            #如果开启了邮件提醒,给作者发送邮件
            author = users.get_user_by_id(aid)
            person = users.get_profile_by_user_id(aid)
            p = postModel.getPostByPostId(pid)  #得到目标post
            if person.has_key(
                    'email_subscribe'
            ) and person.email_subscribe == 1 and author.email:
                email_templates.someone_comment_ur_post(user, author, p)
                print '=== email send =='

        postModel.add_post_comment(comment, uid, pid)
        #得到刚刚添加的comment的id,返回ajax给li添加id 供删除用
        last_comment = postModel.get_just_added_comment(uid, pid).id

        return '{"status": "y", "comment_id": "' + str(last_comment) + '"}'
Example #6
0
        form.notnull, vemail,
        description='邮箱:'),
    form.Password('password', 
        form.notnull,
        description='密码:'),
    validators = [
        form.Validator('邮箱地址或密码不正确', 
            lambda i: users.is_correct_password(i.email, i.password))
    ]
)

register_form = form.Form(
    form.Textbox('username', 
        form.notnull,
        form.Validator('用户名已存在.',
        lambda x: users.is_username_available(x)),
        #form.Validator('请以字母开头,不超过15个字母、数字,保存后不可修改', #todo
        #lambda x: users.is_username_available(x)),
        description='用户名(以字母开头的2-16个字母、数字组合):'),

    form.Textbox('email', 
        form.notnull, vemail,
        form.Validator('邮箱已经存在.', 
        lambda x: users.is_email_available(x)),
        description='邮箱:'),

    form.Password('password', 
        form.notnull,
        form.Validator('密码不能少于6个字符.', 
        lambda x: users.is_valid_password(x)),
        description='密码:'),