예제 #1
0
        public static SYS_UserView Do_Agent_Login(string usercode, string password)
        {
            LINQ_SystemDataContext dc = new LINQ_SystemDataContext();
            string encryptpassword    = Controller_TextEncryption.Encrypt(password, "");

            return((from c in dc.SYS_UserViews where (c.Email.ToLower() == usercode.ToLower() || c.UserCode.ToLower() == usercode.ToLower()) && c.Active == true && c.Password == encryptpassword select c).FirstOrDefault());
        }
예제 #2
0
        public static string do_signup(string fname, string lname, string orgid, string email, string password, string provider)
        {
            var result = Controllers.Controller_Common.do_verifyemail(email);

            if (result != "ok")
            {
                return("Error~ Your email address is invalid!");
            }

            if (IsSystemUserAlreadyExistByEmail(email))
            {
                return("Error~ This email address is already registered!");
            }

            try
            {
                string encryptpassword    = provider == "sbs"? Controller_TextEncryption.Encrypt(password, ""):string.Empty;
                LINQ_SystemDataContext dc = new LINQ_SystemDataContext();
                SYS_User the_record       = new SYS_User
                {
                    UserID      = Guid.NewGuid().ToString(),
                    UserName    = fname.Trim() + " " + lname.Trim(),
                    UserCode    = string.Empty,
                    Email       = email,
                    OrgID       = orgid,
                    Password    = encryptpassword,
                    ContactInfo = string.Empty,
                    CreatedBy   = "4",
                    CreatedOn   = DateTime.Now,
                    ModifiedBy  = "4",
                    ModifiedOn  = DateTime.Now,
                    RoleID      = "32232403-daa3-4a09-9615-a88285ba3735",
                    LastAction  = Guid.NewGuid().ToString(),
                    LastLogin   = DateTime.Now,
                    Active      = true,
                    Note        = string.Empty,
                    Ref_ID      = string.Empty,
                    Ref_Type    = string.Empty
                };

                dc.SYS_Users.InsertOnSubmit(the_record);
                dc.SubmitChanges();

                return("Success~" + the_record.UserID);
            } catch (Exception ex)
            {
                return("Error~" + ex.Message);
            }
        }
예제 #3
0
        public static string Do_Change_Password(string userid, string oldpassword, string newpassword)
        {
            LINQ_SystemDataContext dc = new LINQ_SystemDataContext();
            SYS_User currentuser      = (from c in dc.SYS_Users where c.UserID == userid && c.Password == Controller_TextEncryption.Encrypt(oldpassword, "") && c.Active == true select c).FirstOrDefault();

            if (currentuser != null)
            {
                currentuser.Password   = Controller_TextEncryption.Encrypt(newpassword, "");
                currentuser.ModifiedOn = DateTime.Now;
                currentuser.ModifiedBy = userid;
                currentuser.LastAction = Guid.NewGuid().ToString();
                dc.SubmitChanges();

                return("Success~");
            }
            else
            {
                return("Error~Your Old Password Is Not Valid Please Chack Your Old Password And Try Again");
            }
        }
예제 #4
0
        public static string SaveUser(
            string record_id, string user_id, string user_code, string user_name,
            string user_email, string password, string contactinfo, string note, string role_id, string dep_id, string pos_id,
            string RequestID)
        {
            try
            {
                LINQ_SystemDataContext dc = new LINQ_SystemDataContext();
                SYS_User     the_record   = new SYS_User();
                SYS_UserView the_view     = new SYS_UserView();
                if (record_id == "" || record_id == null)
                {
                    the_record = (from c in dc.SYS_Users where c.UserCode == user_code && c.Active == true && ((user_id == "") || (user_id != "" && c.UserID != user_id)) select c).FirstOrDefault();
                    if (the_record == null)
                    {
                        //Security Check
                        if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "create"))
                        {
                            throw new Exception("No Access.");
                        }

                        string encryptpassword = Controller_TextEncryption.Encrypt(password, "");

                        the_record = new SYS_User()
                        {
                            Password   = encryptpassword,
                            LastLogin  = DateTime.Now,
                            CreatedBy  = user_id,
                            CreatedOn  = DateTime.Now,
                            Active     = true,
                            UserID     = Guid.NewGuid().ToString(),
                            LastAction = Guid.NewGuid().ToString(),
                            Ref_ID     = "",
                            IsLoggedIn = true,
                            Ref_Type   = "",
                            OrgID      = "",
                        };
                        dc.SYS_Users.InsertOnSubmit(the_record);
                    }
                    else
                    {
                        return("DuplicateCode~");
                    }
                }
                else
                {
                    //Security Check
                    if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "update"))
                    {
                        throw new Exception("No Access.");
                    }

                    the_record = (from c in dc.SYS_Users where c.UserID == record_id select c).FirstOrDefault();
                    if (the_record == null)
                    {
                        throw new Exception("System cannot find the record");
                    }
                }

                the_record.ModifiedBy   = user_id;
                the_record.ModifiedOn   = DateTime.Now;
                the_record.LastAction   = Guid.NewGuid().ToString();
                the_record.UserName     = user_name;
                the_record.UserCode     = user_code;
                the_record.Email        = user_email;
                the_record.ContactInfo  = contactinfo;
                the_record.Note         = note;
                the_record.RoleID       = role_id;
                the_record.DepartmentID = dep_id;
                the_record.PositionID   = pos_id;
                dc.SubmitChanges();
                return("Success~" + the_record.UserID);
            }
            catch (Exception ex)
            {
                return("Error~" + ex.Message);
            }
        }
예제 #5
0
        public static Return_login Do_Login(string usercode, string password)
        {
            LINQ_SystemDataContext dc           = new LINQ_SystemDataContext();
            Return_login           return_login = new Return_login();
            string encryptpassword = Controller_TextEncryption.Encrypt(password, "");
            var    the_userview    = (from c in dc.SYS_UserViews
                                      where (c.Email.ToLower() == usercode.ToLower() || c.UserCode.ToLower() == usercode.ToLower() || c.Email == usercode) &&
                                      c.Active == true && c.Password == encryptpassword
                                      select new SYS_UserView
            {
                UserID = c.UserID,
                UserCode = c.UserCode,
                UserName = c.UserName,
                Email = c.Email,
                Ref_Type = c.Ref_Type,
                Ref_ID = c.Ref_ID,
                RoleID = c.RoleID,
                RoleCode = c.RoleCode,
                DepartmentID = c.DepartmentID,
                DepartmentName = c.DepartmentName
            }).FirstOrDefault();

            return_login.user_data = the_userview;

            if (the_userview != null)
            {
                SYS_UserRoleProgramView usercontrol = (from c in dc.SYS_UserRoleProgramViews
                                                       where c.RoleID == the_userview.RoleID && c.ProgramCode == "UserControl"
                                                       select c).FirstOrDefault();
                if (usercontrol != null)
                {
                    Access usercontrol_access = new Access
                    {
                        AllowView          = usercontrol.AllowView,
                        AllowDelete        = usercontrol.AllowDelete,
                        AllowUpdate        = usercontrol.AllowUpdate,
                        AllowCreate        = usercontrol.AllowCreate,
                        AllowDecision      = usercontrol.AllowDecision,
                        AllowAllDepartment = usercontrol.AllowAllDepartment
                    };
                    return_login.UserControl = usercontrol_access;
                }

                SYS_UserRoleProgramView meetingrequst = (from c in dc.SYS_UserRoleProgramViews where c.RoleID == the_userview.RoleID && c.ProgramCode == "MeetingRequest" select c).FirstOrDefault();
                if (meetingrequst != null)
                {
                    Access meetingrequst_access = new Access
                    {
                        AllowView          = meetingrequst.AllowView,
                        AllowDelete        = meetingrequst.AllowDelete,
                        AllowCreate        = meetingrequst.AllowCreate,
                        AllowUpdate        = meetingrequst.AllowUpdate,
                        AllowDecision      = meetingrequst.AllowDecision,
                        AllowAllDepartment = meetingrequst.AllowAllDepartment
                    };
                    return_login.MeetingRequest = meetingrequst_access;
                }

                SYS_UserRoleProgramView sysConfig = (from c in dc.SYS_UserRoleProgramViews where c.RoleID == the_userview.RoleID && c.ProgramCode == "SysConfig" select c).FirstOrDefault();
                if (sysConfig != null)
                {
                    Access sysConfig_access = new Access
                    {
                        AllowView          = sysConfig.AllowView,
                        AllowDelete        = sysConfig.AllowDelete,
                        AllowCreate        = sysConfig.AllowCreate,
                        AllowUpdate        = sysConfig.AllowUpdate,
                        AllowDecision      = sysConfig.AllowDecision,
                        AllowAllDepartment = sysConfig.AllowAllDepartment
                    };
                    return_login.SysConfig = sysConfig_access;
                }

                SYS_UserRoleProgramView meetingAgenda = (from c in dc.SYS_UserRoleProgramViews where c.RoleID == the_userview.RoleID && c.ProgramCode == "MeetingAgenda" select c).FirstOrDefault();
                if (meetingAgenda != null)
                {
                    Access meetingAgenda_access = new Access
                    {
                        AllowView          = meetingAgenda.AllowView,
                        AllowDelete        = meetingAgenda.AllowDelete,
                        AllowCreate        = meetingAgenda.AllowCreate,
                        AllowUpdate        = meetingAgenda.AllowUpdate,
                        AllowDecision      = meetingAgenda.AllowDecision,
                        AllowAllDepartment = meetingAgenda.AllowAllDepartment
                    };
                    return_login.MeetingAgenda = meetingAgenda_access;
                }

                SYS_UserRoleProgramView meetingMinute = (from c in dc.SYS_UserRoleProgramViews where c.RoleID == the_userview.RoleID && c.ProgramCode == "MeetingMinute" select c).FirstOrDefault();
                if (meetingMinute != null)
                {
                    Access meetingMinute_access = new Access
                    {
                        AllowView          = meetingMinute.AllowView,
                        AllowDelete        = meetingMinute.AllowDelete,
                        AllowCreate        = meetingMinute.AllowCreate,
                        AllowUpdate        = meetingMinute.AllowUpdate,
                        AllowDecision      = meetingMinute.AllowDecision,
                        AllowAllDepartment = meetingMinute.AllowAllDepartment
                    };
                    return_login.MeetingMinute = meetingMinute_access;
                }
            }



            return(return_login);
        }