Exemple #1
0
        public Message Auth(string account, string password)
        {
            if (Orleans.GrainClient.IsInitialized == false)
            {
                return(WebService.JSONMessage(new { error = "Client not initialised" }));
            }

            if (account == null) //should never be hit provided no-one touches the templates
            {
                return(WebService.JSONMessage(new { error = "Account name must be provided" }));
            }
            if (password == null) //should never be hit provided no-one touches the templates
            {
                return(WebService.JSONMessage(new { error = "Password must be provided" }));
            }

            IAccount ac = Orleans.GrainClient.GrainFactory.GetGrain <IAccount>(account);

            if (ac == null)
            {
                return(WebService.JSONMessage(new { error = "Internal error: client returned null actor" }));
            }

            var result = ac.Authenticate(password).Result;

            var ret = new
            {
                account          = account,
                auth_result      = result,
                auth_result_enum = result.ToString()
            };

            return(WebService.JSONMessage(ret));
        }
Exemple #2
0
        public async Task <IActionResult> Authenticate([FromBody] User credential)
        {
            IActionResult response = Unauthorized();
            var           user     = await _accountService.Authenticate(credential.UserName, credential.Password);

            if (user != null)
            {
                response = Ok(new { token = user.Token, userid = user.UserID });
            }

            return(response);
        }
Exemple #3
0
 public async Task <IActionResult> Authenticate([FromBody] User user)
 {
     try
     {
         return(Ok(await _account.Authenticate(user.UserName, user.Password)));
     }
     catch (Exception ex)
     {
         //ExceptionLog exception = await _exceptionService.UpsertException(ex, "GetUserRoles", "","");
         return(StatusCode((int)HttpStatusCode.InternalServerError, new CustomMesageError(ex.Message).Message));
     }
 }
Exemple #4
0
        public ActionResult Authenticate(User u)
        {
            int id = account.Authenticate(u);

            if (id == -1)
            {
                return(Redirect("/Account/Login"));
            }
            else
            {
                Session["key"]  = id;
                Session.Timeout = 20;
                return(Redirect("/DashBoard/Index"));
            }
        }
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (account.Authenticate(model.UserName, model.Password))
                {
                    // данные потльзователя
                    List <User> user = new List <User>();
                    user = account.UsersList(model.UserName);

                    // активен ли пользователь
                    if (user[0].IsActive == 1)
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, false);

                        // лог
                        logging.Logged(
                            "Info"
                            , "Пользователь '" + model.UserName + "' вошел в систему"
                            , this.GetType().Namespace
                            , this.GetType().Name
                            );

                        return(Json(new { result = "Redirect", url = Url.Action("Index", "Home") }));
                    }
                    else
                    {
                        // лог
                        logging.Logged(
                            "Error"
                            , "Отказано в доступе: пользователь '" + model.UserName + "' неактивен"
                            , this.GetType().Namespace
                            , this.GetType().Name
                            );

                        ModelState.AddModelError("", "Отказано в доступе");
                    }
                }
                else
                {
                    //// лог
                    //logging.Logged(
                    //      "Error"
                    //    , "Ошибка аутентификации: '" + model.UserName + "' - неправильный логин или пароль"
                    //    , this.GetType().Namespace
                    //    , this.GetType().Name
                    //);

                    ModelState.AddModelError("", "Неправильный логин или пароль");
                }
            }
            //else
            //{
            //    // лог
            //    logging.Logged(
            //            "Error"
            //        , "Ошибка аутентификации: '" + model.UserName + "' - неправильный логин или пароль"
            //        , this.GetType().Namespace
            //        , this.GetType().Name
            //    );

            //    ModelState.AddModelError("", "Ошибка аутентификации");
            //}

            return(PartialView("LoginPartial", model));
        }