Exemple #1
0
        public async Task <ActionResult> Auth(AuthViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Users user = await _systemService.Authenticate(model.UserName, model.Password);

            if (user == null || user.UserId <= 0 || user.ActiveStatus == false)
            {
                model.HasChecked = true;
                return(View(model));
            }
            else
            {
                //_logger.LogInformation("before sign in");

                Helper.Signin(user, HttpContext);

                //_logger.LogInformation("after sign in");

                return(RedirectToAction(nameof(Index)));
            }
        }
Exemple #2
0
        public string Authenticate(string accountName, string userName, string password)
        {
            AuthenticateRequest request = new AuthenticateRequest();

            request.UserName = tbUsername.Text;
            request.Password = tbPassword.Text;
            AuthenticateResponse response = _systemService.Authenticate(request);

            if (response.Success)
            {
                //Redirecting..
                if (response.User.languageId == 3)
                {
                    _systemService.SessionHelper.SetLanguage("ar");
                }
                else
                {
                    _systemService.SessionHelper.SetLanguage("en");
                }

                return("1");//Succeded
            }
            else
            {
                lblError.Text = (String)GetLocalResourceObject(response.Message);
                return("error");//Error in authentication
            }
        }
Exemple #3
0
        private bool HandleExternalUrl()
        {
            string decrypted = EncryptionHelper.decrypt(Request.QueryString["param"], null);
            var    parsed    = HttpUtility.ParseQueryString(decrypted);

            if (string.IsNullOrEmpty(parsed["_a"]) || string.IsNullOrEmpty(parsed["_e"]) || string.IsNullOrEmpty(parsed["_p"]) || string.IsNullOrEmpty(parsed["_c"]))
            {
                return(false);
            }


            UrlKeyRequest reqkey = new UrlKeyRequest();

            reqkey.keyId = Server.UrlEncode(Request.QueryString["param"]);
            _systemService.SessionHelper.Set("AccountId", parsed["_a"]);



            AuthenticateRequest req = new AuthenticateRequest();

            req.UserName = parsed["_e"];
            req.Password = parsed["_p"];
            _systemService.SessionHelper.Set("AccountId", parsed["_a"]);
            AuthenticateResponse resp = _systemService.Authenticate(req);

            if (!resp.Success)
            {
                return(false);
            }
            if (resp.User.languageId == 2)
            {
                _systemService.SessionHelper.SetLanguage("ar");
            }
            else
            {
                _systemService.SessionHelper.SetLanguage("en");
            }
            RecordResponse <KeyId> keyresp = _systemService.ChildGetRecord <KeyId>(reqkey);

            if (!keyresp.Success)
            {
                return(false);
            }
            _systemService.SessionHelper.Set("CompanyName", " ");

            _systemService.SessionHelper.SetUserType(resp.User.userType);
            _systemService.SessionHelper.SetEmployeeId(resp.User.employeeId);
            _systemService.SessionHelper.Set("CurrentUserName", parsed["_e"]);

            _systemService.SessionHelper.Set("IsAdmin", resp.User.isAdmin);
            StoreSystemDefaults();
            string url = PageLookup.GetPageUrlByClassId(Convert.ToInt32(parsed["_c"])) + "?" + parsed["_k"].Replace('#', '&');

            X.Call("openNewTab", parsed["_c"], url, GetGlobalResourceObject("Classes", "Class" + parsed["_c"]), "icon-Employees");
            //Response.Redirect("Default.aspx");
            return(true);
        }
Exemple #4
0
        public string Authenticate(string accountName, string userName, string password)
        {
            GetAccountRequest GetACrequest = new GetAccountRequest();

            GetACrequest.Account = tbAccountName.Text;

            Response <Account> getACResponse = _masterService.GetAccount(GetACrequest);

            if (!getACResponse.Success)
            {
                lblError.Text = getACResponse.Error;
                return("error");//Error in authentication
            }

            _systemService.SessionHelper.Set("AccountId", getACResponse.result.accountId);
            AuthenticateRequest request = new AuthenticateRequest();

            request.UserName = tbUsername.Text;
            request.Password = EncryptionHelper.encrypt(tbPassword.Text);
            AuthenticateResponse response = _systemService.Authenticate(request);

            if (response.User == null)
            {
                if (string.IsNullOrEmpty(response.Error))
                {
                    lblError.Text = GetGlobalResourceObject("Errors", "authenticationError").ToString();
                }
                else
                {
                    lblError.Text = response.Error;
                }

                return("error");
            }
            if ((ActiveStatus)response.User.activeStatus == ActiveStatus.INACTIVE)
            {
                lblError.Text = GetGlobalResourceObject("Errors", "inactiveUser").ToString();
                return("error");
            }
            if (response.Success)
            {
                //Redirecting..
                Response.Cookies.Add(new HttpCookie("accountName", accountName)
                {
                    Expires = DateTime.Now.AddDays(30)
                });
                if (rememberMeCheck.Checked)
                {
                    Response.Cookies.Add(new HttpCookie("email")
                    {
                        Value = userName, Expires = DateTime.Now.AddDays(30),
                    });
                    Response.Cookies.Add(new HttpCookie("password")
                    {
                        Value = password, Expires = DateTime.Now.AddDays(30),
                    });
                }
                else
                {
                    RemoveCookies();
                }
                //switch (response.User.languageId)
                //{
                //    case 1: _systemService.SessionHelper.SetLanguage("en");
                //        break;
                //    case 2:
                //        _systemService.SessionHelper.SetLanguage("ar");
                //        break;
                //    case 3: _systemService.SessionHelper.SetLanguage("fr");
                //        break;
                //    default: _systemService.SessionHelper.SetLanguage("en");
                //        break;

                //}

                _systemService.SessionHelper.SetLanguage("de");

                _systemService.SessionHelper.Set("CompanyName", getACResponse.result.companyName);

                _systemService.SessionHelper.SetUserType(response.User.userType);
                _systemService.SessionHelper.SetEmployeeId(response.User.employeeId);
                _systemService.SessionHelper.Set("CurrentUserName", userName);

                _systemService.SessionHelper.Set("IsAdmin", response.User.isAdmin);
                StoreSystemDefaults();
                return("1");//Succeded
            }
            else
            {
                lblError.Text = response.Error;
                return("error");//Error in authentication
            }
        }