Exemplo n.º 1
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            try
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    if (await AuthenticateManager.CheckEmailExists(entryEmail.Text))
                    {
                        await AuthenticateManager.GetPasswordReset(entryEmail.Text);

                        await Navigation.PopModalAsync();
                    }
                    else
                    {
                        lblMelding.Text = "Het email adress is niet in gebruik";
                    }
                }
                else
                {
                    await DisplayAlert("Opgepast", "Je hebt internet nodig om je wachtwoord te reseten", "Ok");
                }
            }
            catch (Exception ex)
            {
                await StepOutManager.Writelog(ex);
                await DisplayAlert("Melding", "Er is iets misgelopen bij het aanvragen vaan een nieuw passwoord", "Ok");
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> LoginAsync(Authentications authentication)
        {
            //authenticate using the manager

            var usr = AuthenticateManager.GetAuthentication(authentication.Username, authentication.Password);

            if (authentication == null)
            {
                return(View());
            }

            var claims = new List <Claim>()
            {
                new Claim(ClaimTypes.Name, usr.Username),
                new Claim("FullName", usr.Username),
            };

            var claimsIdentity = new ClaimsIdentity(claims, "Cookies");

            await HttpContext.SignInAsync("Cookies", new ClaimsPrincipal(claimsIdentity));

            if (TempData["ReturnUrl"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(Redirect(TempData["ReturnUrl"].ToString()));
            }
        }
Exemplo n.º 3
0
        private async void btnLogin_Clicked(object sender, EventArgs e)
        {
            try
            {
                lblMelding.Text = "";
                if (await CheckConnection())
                {
                    Email = entryName.Text.ToLower();

                    string password = Regex.Replace(entryPass.Text, @"\t|\n|\r", "");
                    if (await AuthenticateManager.CheckUserLogin(Email, password))
                    {
                        Application.Current.Properties["Current_User"] = Email;
                        await Application.Current.SavePropertiesAsync();

                        var answer = await DisplayAlert("Verbinden met hartslag sensor?", "Wilt u verbinden met een hartslag sensor via bluetooth?", "Ja", "Nee");

                        if (answer)
                        {
                            await Navigation.PushModalAsync(new ConnectBluetoothPage());
                        }
                        else
                        {
                            await Navigation.PopModalAsync();

                            //Navigation.RemovePage(this);
                        }


                        //Debug.WriteLine(Navigation.NavigationStack.Count);
                    }
                    else
                    {
                        lblMelding.Text = "Onbekende combinatie";
                    }
                }
                else
                {
                    await DisplayAlert("Waarschuwing", "Zet uw WiFi/4G aan voordat u verder gaat!", "Ok");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                await DisplayAlert("Fout", "Er is iets misgelopen bij het inloggen, als deze fout zich blijft voordoen neemt men best contact op met de support", "OK");
            }
        }
Exemplo n.º 4
0
        public void Authen_Test_Attemp()
        {
            //Arrage
            User   u         = null;
            string idcard    = "0000000000001";
            string firstname = "budgetor";
            User   u2        = context.PersistenceSession.Get <User>(2L);

            IList <iSabaya.UserSession> userSessions = context.PersistenceSession
                                                       .QueryOver <iSabaya.UserSession>()
                                                       .Where(us => us.User.ID == u2.ID && us.SessionPeriod.To == iSabaya.TimeInterval.MaxDate)
                                                       .List();

            foreach (iSabaya.UserSession us in userSessions)
            {
                using (ITransaction tx = context.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        us.SessionPeriod.To = DateTime.Now;
                        us.Save(context);

                        tx.Commit();
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();
                    }
                }
            }

            AuthenticateManager.Authenticate(context, iSabaya.SystemEnum.RiskAssessmentAnalysisSystem, idcard, firstname, ref u);

            AuthenticateManager.AuthenState state = AuthenticateManager.Authenticate(context, iSabaya.SystemEnum.RiskAssessmentAnalysisSystem, idcard, firstname, ref u);


            //Act
            User uAct = context.PersistenceSession.Get <User>(2L);

            AuthenticateManager.AuthenState stateAct = AuthenticateManager.AuthenState.AlreadyLogin;

            //Assert
            Assert.AreEqual(state, stateAct);
            Assert.AreEqual(u, uAct);
        }
Exemplo n.º 5
0
        public void Authen_Test_Success()
        {
            //Arrage
            User   u         = null;
            string idcard    = "0000000000000";
            string firstname = "admin";

            AuthenticateManager.AuthenState state = AuthenticateManager.Authenticate(context, iSabaya.SystemEnum.RiskAssessmentAdminSystem, idcard, firstname, ref u);

            //Act
            User uAct = context.PersistenceSession.Get <User>(1L);

            AuthenticateManager.AuthenState stateAct = AuthenticateManager.AuthenState.AuthenticationSuccess;

            //Assert
            Assert.AreEqual(state, stateAct);
            Assert.AreEqual(u, uAct);
        }
Exemplo n.º 6
0
        public void Authen_Test_Fail()
        {
            //Arrage
            User   u         = null;
            string idcard    = "0000000000000";
            string firstname = "test";

            AuthenticateManager.AuthenState state = AuthenticateManager.Authenticate(context, iSabaya.SystemEnum.RiskAssessmentAdminSystem, idcard, firstname, ref u);

            //Act
            User uAct = null;

            AuthenticateManager.AuthenState stateAct = AuthenticateManager.AuthenState.AuthenticationFail;

            //Assert
            Assert.AreEqual(state, stateAct);
            Assert.AreEqual(u, uAct);
        }
Exemplo n.º 7
0
 public IActionResult Login(
     [FromBody] UserDto userDto,
     [FromServices] AuthenticateManager authenticateManager,
     [FromServices] IUserServiceAuthenticate userService)
 {
     try
     {
         ObjectToken objectToken = authenticateManager.Authenticate(userDto, userService);
         if (objectToken.authenticated)
         {
             return(Ok(objectToken));
         }
         return(Unauthorized());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemplo n.º 8
0
        private async void btnRegister_Clicked(object sender, EventArgs e)
        {
            try
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    if (!IsValidEmail(entryEmail.Text) || string.IsNullOrEmpty(entryEmail.Text))
                    {
                        lblMelding.Text = "Dit is geen geldig emailadres.";
                    }
                    else
                    {
                        if (!await AuthenticateManager.CheckEmailExists(entryEmail.Text))
                        {
                            if (!string.IsNullOrEmpty(entryLand.Text) && !string.IsNullOrEmpty(entryName.Text) && !string.IsNullOrEmpty(entryPass.Text))
                            {
                                await AuthenticateManager.AddUser(entryName.Text, entryPass.Text, entryEmail.Text, entryLand.Text);

                                await Navigation.PopModalAsync();
                            }
                            else
                            {
                                lblMelding.Text = "Gelieve alle velden in te vullen.";
                            }
                        }
                        else
                        {
                            lblMelding.Text = "Email adres is al in gebruik";
                        }
                    }
                }
                else
                {
                    await DisplayAlert("Opgepast", "Je hebt internet nodig voor je te registreren.", "Ok");
                }
            }
            catch (Exception ex)
            {
                await StepOutManager.Writelog(ex);
                await DisplayAlert("Melding", "Er is iet misgelopen bij het registreren, als deze fout zich blijft voordoen kan men beter contact opnemen met de support.", "Ok");
            }
        }
Exemplo n.º 9
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            try
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    lblMelding.Text = "";
                    string password = Regex.Replace(entryOldPass.Text, @"\t|\n|\r", "");
                    if (await AuthenticateManager.CheckUserLogin(Application.Current.Properties["Current_User"].ToString(), password))
                    {
                        if (entrynewPass2.Text == entrynewPass1.Text)
                        {
                            await AuthenticateManager.ResetPassword(Application.Current.Properties["Current_User"].ToString(), entrynewPass2.Text);

                            await Navigation.PopAsync();
                        }
                        else
                        {
                            lblMelding.Text = "De 2 opgegeven nieuwe wachtwoorden zijn niet gelijk.";
                        }
                    }
                    else
                    {
                        lblMelding.Text = "Oude wachtwoord is niet correct";
                    }
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Opgepast", "voor je wachtwoord opnieuw in te stellen heb je internet nodig.", "Ok");
                }
            }
            catch (Exception ex)
            {
                await StepOutManager.Writelog(ex);

                await App.Current.MainPage.DisplayAlert("Melding", "Er is iets foutgelopen bij het herinstellen van het wachtwoord, controleer of je niet een spatie teveel hebt. Als dit niet het geval is en het werkt nog niet neem je best even contact op met de support.", "ok");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取token
        /// </summary>
        /// <param name="staff">The staff.</param>
        /// <returns>System.String.</returns>
        private static string GetToken(MStaffInfo staff)
        {
            if (staff != null)
            {
                string crossOOSerivceUrl = ConfigurationManager.AppSettings["SOOUrl"] + "/LoginInfoValidate.aspx";
                AuthenticateManager authManager = new AuthenticateManager(crossOOSerivceUrl, "Change", staff.Staff_id, staff.Department_id.ToString(), staff.Department, string.Empty);
                if (authManager.Login())
                {
                    return authManager.Token;
                }
            }

            return string.Empty;
        }
Exemplo n.º 11
0
        /// <summary>
        /// 老单点登录方式
        /// </summary>
        /// <returns>执行结果</returns>
        private ActionResult SSOUrl()
        {
            // 共享登陆
            if (this.Request["PartnerId"] != null)
            {
                try
                {
                    AuthenticateManager manager = new AuthenticateManager(
                        System.Web.HttpContext.Current.Request,
                        ConfigurationManager.AppSettings["SOOUrl"] + "/LoginInfoValidate.aspx");
                    //// 登陆成功
                    if (manager.Validate())
                    {
                        TrackIdManager.GetInstance(manager.AccountId);

                        //// 获取用户对象
                        UserLoginServiceHelper.UserLoginServiceHelper userHelper =
                            new UserLoginServiceHelper.UserLoginServiceHelper();

                        MStaffInfo staff = userHelper.GetStaffInfoModel(manager.AccountId);
                        ////登录用户不为平台时限制ip
                        int staffType = staff.StaffType;
                        if (staffType != 1)
                        {
                           if (!userHelper.LimitIpLogin(staff.Department_id, this.GetIpAddr()))
                           {
                               return this.Json("当前登录IP不在允许的登录IP范围内!", "text/html", JsonRequestBehavior.AllowGet);
                           }
                        }

                        ////  平台才能登陆 
                        if (staff.StaffType != 1)
                        {
                            this.TempData["ResMsg"] = "当前账号无权限";
                            return this.View("ErrorPage");
                        }
                        else
                        {
                            //// 登陆成功
                            FormsAuthentication.SetAuthCookie(staff.Staff_id, false);
                            this.SetLocalTicket(staff);

                            //// 保存会话Token
                            this.Session["Token"] = manager.Token;

                            //// TODO 保存用户对象
                            this.Session["$sessionName$_UserInfo"] = staff;

                            //// 页面跳转
                            if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request["RequestPage"]))
                            {
                                return this.Redirect("~/" + HttpUtility.UrlDecode(System.Web.HttpContext.Current.Request["RequestPage"]));
                            }
                            else
                            {
                                return this.Redirect("~/Home/Index");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // 单点登录失败吃掉异常
                    AppException appEx = new AppException(string.Empty, ex.Message, ex, null);
                    LogManager.Log.WriteException(appEx);
                }
            }
            else
            {
                this.ViewData["result"] = null;
            }

            return this.View();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthenticateManagerTests"/> class.
 /// </summary>
 public AuthenticateManagerTests()
 {
     this.authenticateRepository = new Mock<IAuthenticateRepository>();
     this.authenticateManager = new AuthenticateManager(this.authenticateRepository.Object);
 }
Exemplo n.º 13
0
        public string Authentication(string idCard, string nameEng, string status)
        {
            try
            {
                WebLogger.Warn("Authenticating");

                Dictionary <string, object> jsonResult = new Dictionary <string, object>();

                User user = null;

                switch (AuthenticateManager.Authenticate(SessionContext, SystemEnum.RiskAssessmentAnalysisSystem, idCard, nameEng, ref user))
                {
                case AuthenticateManager.AuthenState.AuthenticationSuccess:

                    BudgetConfiguration.CurrentConfiguration = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID);
                    SessionContext.StartNewSession(user, Session.SessionID);

                    string targetPath = "";
                    switch (user.UserRoles[0].Role.Id)
                    {
                    case 1:
                        targetPath = FullUrl("Government");        //ส่วนราชการ
                        break;

                    case 2:
                        targetPath = FullUrl("Budgetor");        //ทำงบประมาณ
                        break;

                    case 3:
                        targetPath = FullUrl("Evaluation");        //เจ้าหน้าที่ประเมินงบ
                        break;

                    case 4:
                        targetPath = FullUrl("Admin");        //ผู้ดูแลระบบ
                        break;

                    default:
                        throw new Exception("User Role Invalid.");
                    }

                    jsonResult.Add("result", 1);
                    jsonResult.Add("target", targetPath);
                    jsonResult.Add("message", "");
                    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString()));
                    break;

                case AuthenticateManager.AuthenState.AuthenticationFail:
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(string.Format("{0} : {1}", idCard, nameEng)));
                    break;

                case AuthenticateManager.AuthenState.AlreadyLogin:
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(user.ID.ToString() + " : Login Attemp."));
                    break;

                default:
                    break;
                }

                WebLogger.Warn("End Authenticating");

                return(new JavaScriptSerializer().Serialize(jsonResult));

                #region old

                //Dictionary<string, object> jsonResult = new Dictionary<string, object>();
                //IList<SelfAuthenticatedUser> users = SessionContext.PersistenceSession.QueryOver<SelfAuthenticatedUser>().List();
                //IList<SelfAuthenticatedUser> user = users.Where(s => s.LoginName.ToLowerInvariant() == nameEng.ToLowerInvariant()
                //        && s.Person.OfficialIDNo == idCard
                //        && s.UserRoles[0].Role.Id == int.Parse(status)
                //        && !s.IsDisable
                //        && s.IsEffective).ToList();

                //if (0 < user.Count)
                //{
                //    if (user.Count != 1) { throw new Exception("User have more than one. System error."); }

                //    //if (!user[0].IsBuiltin)
                //    //{
                //    //    IList<iSabaya.UserSession> userSessions = SessionContext.PersistenceSession
                //    //        .QueryOver<iSabaya.UserSession>()
                //    //        .Where(us => us.User.ID == user[0].ID
                //    //            && us.SessionPeriod.To == iSabaya.TimeInterval.MaxDate)
                //    //        .List();

                //    //    if (userSessions.Any(u => u.User.ID == user[0].ID))
                //    //    {
                //    //        jsonResult.Add("result", 0);
                //    //        jsonResult.Add("target", "");
                //    //        jsonResult.Add("message", "Login Failed.");
                //    //        SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(userSessions[0].User.ID.ToString() + " : Login Attemp."));
                //    //        //SessionContext.StartFailedSession(null, idCard, Session.SessionID, "Login Attemp.");

                //    //        return new JavaScriptSerializer().Serialize(jsonResult);
                //    //    }
                //    //}

                //    BudgetConfiguration.CurrentConfiguration = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID);
                //    SessionContext.StartNewSession(user[0], Session.SessionID);

                //    string targetPath = "";
                //    switch (user[0].UserRoles[0].Role.Id)
                //    {
                //        //case 1:
                //        //    targetPath = FullUrl("Government");//ส่วนราชการ
                //        //    break;
                //        case 2:
                //            targetPath = FullUrl("Budgetor");//ทำงบประมาณ
                //            break;
                //        case 3:
                //            targetPath = FullUrl("Evaluation");//เจ้าหน้าที่ประเมินงบ
                //            break;
                //        //case 4:
                //        //    targetPath = FullUrl("Admin");//ผู้ดูแลระบบ
                //        //    break;
                //        default:
                //            throw new Exception("User Role Invalid.");
                //    }

                //    jsonResult.Add("result", 1);
                //    jsonResult.Add("target", targetPath);
                //    jsonResult.Add("message", "");
                //    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString()));
                //}
                //else
                //{
                //    jsonResult.Add("result", 0);
                //    jsonResult.Add("target", "");
                //    jsonResult.Add("message", "Login Failed.");
                //    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail());
                //    //SessionContext.StartFailedSession(null, idCard, Session.SessionID, "Login Failed.");
                //}

                //WebLogger.Warn("End Authenticating");
                //return new JavaScriptSerializer().Serialize(jsonResult);

                #endregion old
            }
            catch (Exception ex)
            {
                WebLogger.Error(ex.GetAllMessages());

                Dictionary <string, object> jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 0);
                jsonResult.Add("target", "");
                jsonResult.Add("message", ex.ToString());

                //SessionContext.StartFailedSession(null, idCard, Session.SessionID, ex.Message);

                SessionContext.Log(0, this.pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(ex.Message));

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
        }
Exemplo n.º 14
0
        public string Authentication(string idCard, string nameEng, string status)
        {
            try
            {
                SessionContext.PersistenceSession.Clear();
                WebLogger.Warn("Authenticating");
                var  jsonResult = new Dictionary <string, object>();
                User user       = null;
                BudgetConfiguration.CurrentConfiguration
                    = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID);

                switch (AuthenticateManager
                        .Authenticate(SessionContext,
                                      SystemEnum.RiskAssessmentProjectOwnerSystem,
                                      idCard,
                                      nameEng,
                                      ref user))
                {
                case AuthenticateManager.AuthenState.AuthenticationSuccess:

                    SessionContext.StartNewSession(user, Session.SessionID);

                    var targetPath = "";
                    switch (user.UserRoles[0].Role.Id)
                    {
                    case 1:
                        targetPath = FullUrl("Government");        //ส่วนราชการ
                        break;

                    case 2:
                        targetPath = FullUrl("Budgetor");        //ทำงบประมาณ
                        break;

                    case 3:
                        targetPath = FullUrl("Evaluation");        //เจ้าหน้าที่ประเมินงบ
                        break;

                    case 4:
                        targetPath = FullUrl("Admin");        //ผู้ดูแลระบบ
                        break;

                    default:
                        throw new Exception("User Role Invalid.");
                    }

                    jsonResult.Add("result", 1);
                    jsonResult.Add("target", targetPath);
                    jsonResult.Add("message", "");
                    SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString()));
                    break;

                case AuthenticateManager.AuthenState.AuthenticationFail:
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(string.Format("{0} : {1}", idCard, nameEng)));
                    break;

                case AuthenticateManager.AuthenState.AlreadyLogin:
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(user.ID.ToString() + " : Login Attemp."));
                    break;

                default:
                    break;
                }

                WebLogger.Warn("End Authenticating");

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
            catch (Exception ex)
            {
                WebLogger.Error(ex.GetAllMessages());

                var jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 0);
                jsonResult.Add("target", "");
                jsonResult.Add("message", ex.ToString());

                SessionContext.StartFailedSession(null, idCard, Session.SessionID, ex.Message);
                SessionContext.Log(0, this.PageID, 0, "Login", "Fail : " + ex.Message);

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
        }