Ejemplo n.º 1
0
 public static void ResetPassword(BizPortalSessionContext context, MemberUser memberUser)
 {
     using (ITransaction tx = context.PersistenceSession.BeginTransaction())
     {
         try
         {
             SelfAuthenticatedUser u = ((SelfAuthenticatedUser)memberUser);
             u.ResetPassword(context.Configuration.Security.PasswordPolicy, "aA=00000");
             u.Persist(context);
             tx.Commit();
         }
         catch (Exception)
         {
             tx.Rollback();
             throw;
         }
     }
 }
Ejemplo n.º 2
0
        private static void InitAdminUser()
        {
            Organization          org     = context.PersistenceSession.Get <Organization>(1L);
            OrgUnit               orgUnit = org.OrgUnits.Where(x => x.Code == "01007").SingleOrDefault();
            SelfAuthenticatedUser admin   = new SelfAuthenticatedUser
                                            (
                SystemEnum.RiskAssessmentAdminSystem, //SessionContext.MySystem.SystemID,
                org,                                  //org,
                orgUnit,                              //orgUnit,
                "0000000000000",                      //idCard,
                "admin",                              //loginName,
                "แอดมิน",                             //firstNameTH,
                "admin",                              //firstNameEN,
                "แอดมิน",                             //lastNameTH,
                "admin",                              //lastNameEN,
                "",                                   //middleNameTH,
                "",                                   //middleNameEN,
                "",                                   //email,
                "",                                   //mobilePhone,
                "",                                   //telephone,
                "",                                   //toNumber,
                "",                                   //directTelephone
                "",                                   //Address
                true
                                            );

            admin.EffectivePeriod = TimeInterval.EffectiveNow;
            admin.UserRoles       = new List <UserRole>
            {
                new UserRole {
                    User            = admin,
                    Role            = context.PersistenceSession.QueryOver <Role>().Where(x => x.SystemID == SystemEnum.RiskAssessmentAdminSystem).SingleOrDefault(),
                    EffectivePeriod = TimeInterval.EffectiveNow,
                }
            };

            admin.Persist(context);
        }
Ejemplo n.º 3
0
        public JsonResult Register(string idcard, string firstNameTH, string lastNameTH, string firstNameEN,
                                   string lastNameEN, string address, string telephone, string toNumber, string phoneIn, string smartPhone,
                                   string email, string status, long ministry, long departments)
        {
            try
            {
                if (string.IsNullOrEmpty(idcard) && string.IsNullOrEmpty(firstNameTH) &&
                    string.IsNullOrEmpty(lastNameTH) && string.IsNullOrEmpty(firstNameEN) &&
                    string.IsNullOrEmpty(lastNameEN) && string.IsNullOrEmpty(address) &&
                    string.IsNullOrEmpty(email) && string.IsNullOrEmpty(status) &&
                    ministry == 0 && departments == 0)
                {
                    return(Json(new { Success = false, Message = "กรุณาตรวจสอบข้อมูล" }, JsonRequestBehavior.AllowGet));
                }

                if (SessionContext.PersistenceSession.QueryOver <iSabaya.User>().List().Any(x => x.Person.OfficialIDNo == idcard))
                {
                    return(Json(new { Success = false, Message = "เลขบัตรประชาชนนี้ได้ลงทะเบียนแล้ว ไม่สามารถลงทะเบียนซ้ำได้" }, JsonRequestBehavior.AllowGet));
                }

                Organization org     = Organization.Find(SessionContext, ministry);
                OrgUnit      orgUnit = OrgUnit.Find(SessionContext, departments);

                SelfAuthenticatedUser user = new SelfAuthenticatedUser(
                    SessionContext.MySystem.SystemID,
                    org,
                    orgUnit,
                    idcard,
                    firstNameEN,
                    firstNameTH, firstNameEN,
                    lastNameTH, lastNameEN,
                    "", "",
                    email,
                    smartPhone, telephone, toNumber, phoneIn, address);

                user.UserRoles = new List <UserRole>
                {
                    new UserRole(user, SessionContext.PersistenceSession.QueryOver <iSabaya.Role>().List().SingleOrDefault(x => x.SystemID == SystemEnum.RiskAssessmentProjectOwnerSystem))
                };

                // user is first register , user is not active and then administrator activate
                user.IsDisable = true;
                // set is not finali flag to admin activate and update approve action
                user.IsNotFinalized = true;

                using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        user.Persist(SessionContext);
                        tx.Commit();

                        SessionContext.Log(0, PageID, 0, "User Register : " + user.LoginName, "Success");
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();

                        SessionContext.LogButNotFlush(0, PageID, 0, "User Register : " + user.LoginName, "Fail : " + ex.Message);
                        return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                    }
                }

                return(Json(new { Success = true, Message = "บันทึกเรียบร้อย" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                SessionContext.LogButNotFlush(0, PageID, 0, "User Register", "Fail : " + ex.Message);
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 4
0
        public JsonResult RegisterStaff(string idCard, string firstNameTH, string lastNameTH,
                                        string firstNameEN, string lastNameEN, string address, string telephone, string toNumber, string directTelephone
                                        , string mobilePhone, string email, string institute, int roleId, long ministryId, long[] agencies)
        {
            try
            {
                if (string.IsNullOrEmpty(idCard) || string.IsNullOrEmpty(firstNameTH) || string.IsNullOrEmpty(lastNameTH) || string.IsNullOrEmpty(firstNameEN) ||
                    string.IsNullOrEmpty(lastNameEN) || string.IsNullOrEmpty(address) || string.IsNullOrEmpty(email) ||
                    roleId < 0 || ministryId < 0 || agencies.Length <= 0)
                {
                    return(Json(new { Success = true, Message = "กรุณาตรวจสอบข้อมูล" }, JsonRequestBehavior.AllowGet));
                }

                if (SessionContext.PersistenceSession.QueryOver <iSabaya.User>().List().Any(x => x.Person.OfficialIDNo == idCard))
                {
                    return(Json(new { Success = false, Message = "เลขบัตรประชาชนนี้ได้ลงทะเบียนแล้ว ไม่สามารถลงทะเบียนซ้ำได้" }, JsonRequestBehavior.AllowGet));
                }

                Organization org     = SessionContext.PersistenceSession.QueryOver <Organization>().Where(o => o.Code == "01000").SingleOrDefault(); //กระทรวงสำนักนายกรัฐมนตรี 01000
                OrgUnit      orgUnit = SessionContext.PersistenceSession.QueryOver <OrgUnit>().Where(o => o.Code == "01007").SingleOrDefault();      //หน่วยงาน สำนักงบประมาณ 01007

                SelfAuthenticatedUser user = new SelfAuthenticatedUser(
                    SessionContext.MySystem.SystemID,
                    org,
                    orgUnit,
                    idCard,
                    firstNameEN,
                    firstNameTH, firstNameEN,
                    lastNameTH, lastNameEN,
                    "", "",
                    email,
                    mobilePhone, telephone, toNumber, directTelephone, address);

                // user is first register , user is not active and then administrator activate
                user.IsDisable = true;
                // set is not finali flag to admin activate and update approve action
                user.IsNotFinalized = true;

                user.UserRoles = new List <UserRole>
                {
                    new UserRole(user, SessionContext.PersistenceSession
                                 .QueryOver <iSabaya.Role>().List()
                                 .SingleOrDefault(x => x.Id == roleId))
                };

                IList <UserOrgUnit> userOrgUnits = new List <UserOrgUnit>();
                for (int i = 0; i < agencies.Length; i++)
                {
                    userOrgUnits.Add(new UserOrgUnit(user, OrgUnit.Find(SessionContext, agencies[i])));
                }

                user.ResponsibleOrgUnits = userOrgUnits;

                using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        user.Persist(SessionContext);
                        tx.Commit();

                        SessionContext.Log(0, pageID, 0, MessageException.RegisterMessage.StaffRegister, MessageException.Success(user.LoginName));
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();

                        SessionContext.Log(0, pageID, 0, MessageException.RegisterMessage.StaffRegister, MessageException.Fail(ex.Message));
                        return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                    }
                }

                return(Json(new { Success = true, Message = "บันทึกเรียบร้อย" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                SessionContext.Log(0, pageID, 0, MessageException.RegisterMessage.StaffRegister, MessageException.Fail(ex.Message));
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }
        }