コード例 #1
0
ファイル: DbTest.cs プロジェクト: agluque62/sacta-proxy
 public void TestMethod2()
 {
     Assert.IsTrue(SystemUsers.Authenticate("1", "1"));
     Assert.IsFalse(SystemUsers.Authenticate("hola", ""));
 }
コード例 #2
0
        public void Start(int port, int SessionDuration = 15, Dictionary <string, wasRestCallBack> cbs = null)
        {
            /** Rutina a la que llama el servidor base para autentificar un usuario */
            AuthenticateUser = (data, response) =>
            {
                /** 'namecontroluser'=user&'namecontrolpwd'=pwd */
                var items = data.Split('&')
                            .Where(x => !string.IsNullOrEmpty(x))
                            .Select(x => x.Split('='))
                            .ToDictionary(x => x[0], x => x[1]);

                if (items.Keys.Contains("username") && items.Keys.Contains("password"))
                {
                    var res   = SystemUsers.Authenticate(items["username"], items["password"]);
                    var cause = res ? "" : "Usuario o password incorrecta";
                    response(res, cause);
                    UserActivityEvent?.Invoke(this, new WebUserActivityArgs()
                    {
                        User = items["username"], InOut = res, Cause = cause
                    });
                }
                else
                {
                    response(false, "No ha introducido usuario o password");
                }
            };

            /** Configura las rutinas a las que llama el servidor base cuando recibe peticiones REST */
            Dictionary <string, wasRestCallBack> cfg = new Dictionary <string, wasRestCallBack>()
            {
                { "/alive", RestAlive },
                { "/logs", RestLogs },
                { "/logout", RestLogout }
            };
            var SecureUris = new List <string>()
            {
                "/styles/bootstrap/bootstrap.min.css",
                "/styles/ncc-styles.css",
                "/scripts/jquery/jquery-2.1.3.min.js",
                "/images/corporativo-a.png",
                "/favicon.ico"
            };

            try
            {
                /** Añado los callback 'exteriores' */
                if (cbs != null)
                {
                    foreach (var item in cbs)
                    {
                        if (cfg.Keys.Contains(item.Key) == false)
                        {
                            cfg[item.Key] = item.Value;
                        }
                    }
                }

                base.Start(port, new CfgServer()
                {
                    DefaultDir      = "/webclient",
                    DefaultUrl      = "/index.html",
                    LoginUrl        = "/login.html",
                    LogoutUrl       = "/logout",
                    LoginErrorTag   = "<div id='result'>",
                    HtmlEncode      = false,
                    SessionDuration = SessionDuration,
                    SecureUris      = SecureUris,
                    CfgRest         = cfg
                });
                stdcontrol.Set(ProcessStates.Running);
            }
            catch (Exception x)
            {
                Logger.Exception <SactaProxyWebApp>(x);
                stdcontrol.SignalFatal <SactaProxyWebApp>($"Excepcion en el arranque => {x.Message}", History());
            }
        }