Exemplo n.º 1
0
def user_add_mail(user, kwargs):
    """
    add user send mail
    发送用户添加邮件
    """
    user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'}
    mail_title = u'恭喜你的跳板机用户 %s 添加成功 Jumpserver' % user.name
    mail_msg = u"""
	Hi, %s
        您的用户名: %s
        您的权限: %s
        您的跳板机Web平台密码: %s
        SSH私钥下载地址: %s/juser/key/down/?uuid=%s
        Web登入地址:http://gk.fangdd.net
        说明: 请通过以上连接下载SSH私钥, 然后使用SSH私钥登陆跳板机.
        请妥善保管好该邮件内容的信息以及私钥文件,如有丢失,请贿赂IOPS成员吃饭以便新建....
	跳板机的任何使用问题,请咨询张雯豪.
	============================================================================
	Usage:
	For UNIX-Like System
	chmod 600 /path/to/your/ssh_privite_key_file.pem
	ssh -i /path/to/your/ssh_privite_key_file.pem <username>@gk.fangdd.net

	For Windows 
	客户端下载链接
	%s/docs/SeureCRT.rar
	客户端配置文档
	%s/docs/SecureCRT4Windows.pdf
	============================================================================
	
    """ % (user.name, user.username, user_role.get(user.role, u'普通用户'),
#           kwargs.get('password'), kwargs.get('ssh_key_pwd'), URL, user.uuid, URL)
           kwargs.get('password'), URL, user.uuid, URL, URL)

    task_mail.delay(mail_title, mail_msg, MAIL_FROM, [user.email])
Exemplo n.º 2
0
def send_mail_retry(request):
    uuid_r = request.GET.get('uuid', '1')
    user = get_object(User, uuid=uuid_r)
    msg = u"""
    跳板机地址: %s
    用户名:%s
    重设密码:%s/juser/password/forget/
    请登录web点击个人信息页面重新生成ssh密钥
    """ % (URL, user.username, URL)

    try:
        task_mail.delay(u'邮件重发', msg, MAIL_FROM, [user.email])
        # send_mail(u'邮件重发', msg, MAIL_FROM, [user.email], fail_silently=False)
    except IndexError:
        return Http404
    return HttpResponse('发送成功')
Exemplo n.º 3
0
def forget_password(request):
    if request.method == 'POST':
        defend_attack(request)
        email = request.POST.get('email', '')
        username = request.POST.get('username', '')
        name = request.POST.get('name', '')
        user = get_object(User, username=username, email=email, name=name)
        if user:
            timestamp = int(time.time())
            hash_encode = PyCrypt.md5_crypt(
                str(user.uuid) + str(timestamp) + KEY)
            msg = u"""
            Hi %s, 请点击下面链接重设密码!
            %s/juser/password/reset/?uuid=%s&timestamp=%s&hash=%s
            """ % (user.name, URL, user.uuid, timestamp, hash_encode)
            task_mail.delay('忘记跳板机密码', msg, MAIL_FROM, [email])
            # send_mail('忘记跳板机密码', msg, MAIL_FROM, [email], fail_silently=False)
            msg = u'请登陆邮箱,点击邮件重设密码'
            return http_success(request, msg)
        else:
            error = u'用户不存在或邮件地址错误'

    return render_to_response('juser/forget_password.html', locals())
Exemplo n.º 4
0
def mail_notify(title, msg, user):
    task_mail.delay(title, msg, MAIL_FROM, [user.email])
Exemplo n.º 5
0
def user_edit(request):
    header_title, path1, path2 = '编辑用户', '用户管理', '编辑用户'
    if request.method == 'GET':
        user_id = request.GET.get('id', '')
        if not user_id:
            return HttpResponseRedirect(reverse('index'))

        user_role = {'SU': u'超级管理员', 'CU': u'普通用户'}
        user = get_object(User, id=user_id)
        group_all = UserGroup.objects.all()
        if user:
            groups_str = ' '.join(
                [str(group.id) for group in user.group.all()])
            admin_groups_str = ' '.join([
                str(admin_group.group.id)
                for admin_group in user.admingroup_set.all()
            ])

    else:
        user_id = request.GET.get('id', '')
        password = request.POST.get('password', '')
        name = request.POST.get('name', '')
        email = request.POST.get('email', '')
        groups = request.POST.getlist('groups', [])
        role_post = request.POST.get('role', 'CU')
        admin_groups = request.POST.getlist('admin_groups', [])
        extra = request.POST.getlist('extra', [])
        is_active = True if '0' in extra else False
        email_need = True if '1' in extra else False
        user_role = {'SU': u'超级管理员', 'CU': u'普通用户'}

        if user_id:
            user = get_object(User, id=user_id)
        else:
            return HttpResponseRedirect(reverse('user_list'))

        if len(password) > 0:
            if not checkPassword(password):
                error = '密码过于简单,至少8位,且包含大小写字母及数字和特殊字符四种中的三种,\
                为方便记忆,请与OA密码保持一致,该密码非明文保存'

                return my_render('juser/user_edit.html', locals(), request)

        db_update_user(user_id=user_id,
                       password=password,
                       name=name,
                       email=email,
                       groups=groups,
                       admin_groups=admin_groups,
                       role=role_post,
                       is_active=is_active)

        if email_need:
            msg = u"""
            Hi %s:
                您的信息已修改,请登录跳板机查看详细信息
                地址:%s
                用户名: %s
                密码:%s (如果密码为None代表密码为原密码)
                权限::%s

            """ % (user.name, URL, user.username, password,
                   user_role.get(role_post, u''))
            task_mail.delay('您的信息已修改', msg, MAIL_FROM, [email])
            # send_mail('您的信息已修改', msg, MAIL_FROM, [email], fail_silently=False)

        return HttpResponseRedirect(reverse('user_list'))
    return my_render('juser/user_edit.html', locals(), request)