}, { "name": "password_length", "default": 8, "help": '', "type": int }, { "name": "pwd_types", "default": 2, "help": '', "type": int }, ] options = get_options(plugins_utils_opts) def check_user_name(user_name): """user name must be e_mail""" pat = re.compile( r'^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+){0,4}@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+){0,4}$' ) ret = re.match(pat, user_name) if not ret: em = "user name :<{0}> is not valid. user name must be e_mail".format( user_name) LOG.exception(em) return False return True
# -*- coding:utf-8 -*- from __future__ import unicode_literals import json import tornado.web from ops_sia.plugins.JsonResponses import BaseHander from ops_sia.plugins.code_auth import CodeAuth from ops_sia.utils import get_token from ops_sia.api.auth import auth as Auth from ops_sia.cache import Backend from ops_sia.options import get_options options = get_options() import ops_sia.log as logging LOG = logging.getLogger(__name__) url_map = { r"/auth_code": "AuthCodeApi", # r"/usr/getuserid": "GetIdByUserName" } class AuthCodeApi(BaseHander, Auth.Base): def get(self): session_id = self.get_argument("session_id", "").strip() obj = CodeAuth() img, code_str = obj.gene_code() self.set_header("Content-type", "image/png")
service_opts = [ { "name": 'report_interval', "default": 30, "help": 'seconds between nodes reporting state to datastore', "type": int, }, { "name": 'periodic_interval', "default": 60, "help": 'seconds between running periodic tasks', "type": int, }, ] options = get_options(service_opts, 'services') class Launcher(object): """Launch one or more services and wait for them to complete.""" def __init__(self): """Initialize the service launcher. :returns: None """ self._services = [] @staticmethod def run_server(server): """Start and wait for a server to finish.
from ops_sia.db.models import db_session, AuthInfo, RegisterPhones, Images from ops_sia.plugins.sms_auth import SendSmsMsg from ops_sia.plugins.upload_file import get_pictuer_url LOG = logging.getLogger(__name__) users_tencent_opts = [ { "name": "ccccc", "default": "", "help": '', "type": str }, ] options = get_options(users_tencent_opts) class RealNameAuth(object): @staticmethod def add_auth_info(data): # 不能重复申请 result = AuthInfo.query.filter( and_( AuthInfo.deleted == False, AuthInfo.user_id == data.user_id, )).first() if result: return {"code": 1, "message": u"请勿重复提交申请"} # 检查手机是否被注册 result_old = RegisterPhones.query.filter(
{ "name": "send_register_timeout", "default": 86400, "help": '', "type": int }, { "name": "old_platform_userid_ep", "default": 'http://10.2.0.61:8108/entity/bss_db/b_customer_info?custom_account=', "help": "old platform get user's end point", "type": str }, ] options = get_options(users_opts) class UserManager(object): @staticmethod def add_user(user_name, password, description=""): """add user to openstack""" try: # check user_name is it valid if not check_user_name(user_name): return False, 400 # check password is it strong if not check_password(password): return False, 400 admin_token = get_token()
from ops_sia.options import get_options auth_opts = [{ "name": "cached_backend", "default": 'redis://127.0.0.1:6379/0', "help": 'cached backend uri', "type": str, }, { "name": 'cache_timeout', "default": '290', "help": 'cache timeout seconds', "type": str, }] options = get_options(auth_opts, 'cache') class Backend(object): def __init__(self): cached_backend = options.cached_backend _conn = cached_backend.split("//")[1] if '@' in _conn: passwd, host_port = _conn.split('@') else: passwd = None host_port = _conn if passwd: passwd = passwd[1:] host, db_p = host_port.split(':') port, db = db_p.split('/')
from ops_sia import cache from ops_sia import utils from ops_sia import log as logging from ops_sia.service import db as service_db auth_opts = [ { "name": "policy", "default": "ops_sia.api.auth.policy", "help": "", "type": str, }, ] options = get_options(auth_opts, 'auth') LOG = logging.getLogger() def load_policy(): option_split = options.policy.split(".") mod = option_split[0] fun = options.policy[options.policy.rfind('.') + 1:] fn_, modpath, desc = imp.find_module(mod) fn_, path, desc = imp.find_module( fun, [os.path.join(modpath, "/".join(option_split[1:-1]))]) return imp.load_module(fun, fn_, path, desc) class BaseAuth(tornado.web.RequestHandler):