public ActionResult Login(SEC_USERS sec_user) { SEC_USERS_LOGIN_Result1 user = db.SEC_USERS_LOGIN(sec_user.USER_NAME, sec_user.USER_PWD, null).FirstOrDefault(); if (user != null && user.USER_NO > 0) { Session["sess_sec_users"] = user; Session["sess_USER_NO"] = user.USER_NO; if (user.USER_TYPE_NO == (decimal)EUserTypes.Agent) { Session["sess_entry_user_no"] = user.USER_NO; Session["sess_zm_user_no"] = user.USER_PARENT_NO; Session["sess_agent_user_no"] = user.USER_NO; } else { Session["sess_entry_user_no"] = user.USER_NO; Session["sess_zm_user_no"] = user.USER_NO; Session["sess_agent_user_no"] = null; } bool Is_ZonalOrAgent = ((decimal)user.USER_TYPE_NO == (decimal)EUserTypes.ZonalManager || (decimal)user.USER_TYPE_NO == (decimal)EUserTypes.Agent); Session["sess_Is_ZonalOrAgent"] = Is_ZonalOrAgent; string sess_id = Session.SessionID; string ip_addr = CustomValidator.GetRequestIpAddress(); string device_id = CustomValidator.GetDeviceId(); string login_mobile = sec_user.USER_MOBILE; string ws_id = CustomValidator.GetWebServerId(); string app_version = sec_user.APP_VERSION; decimal LOGON_NO = db.SEC_USER_LOGONS_INSERT(user.USER_NO, ip_addr, device_id, null, null, null, (decimal)ApproveType.Approved, null, null, sess_id, login_mobile, ws_id, app_version, login_mobile).First().Value; Session["sess_LOGON_NO"] = LOGON_NO; if (user.USER_TYPE_NO == (decimal)EUserTypes.GeneralUser) { List <SET_USER_ACTION> per_list = new List <SET_USER_ACTION>(); per_list = db.SET_USER_ACTION.Include(a => a.GEN_CONTROLLER_ACTION) .Where(a => (a.USER_NO == user.USER_NO) && (a.IS_ACTIVE == 1)) .ToList(); List <GEN_CONTROLLER_ACTION> menu_list = (from c in per_list where (c.GEN_CONTROLLER_ACTION.IS_MENU == 1 && c.GEN_CONTROLLER_ACTION.IS_ACTIVE == 1 ) orderby c.GEN_CONTROLLER_ACTION.SL_NUM select c.GEN_CONTROLLER_ACTION).ToList(); Session["sess_MENU_LIST"] = menu_list; Session["sess_PERMISSION_LIST"] = per_list; if (menu_list != null) { GEN_CONTROLLER_ACTION redirect_action = menu_list.First(); return(RedirectToAction(redirect_action.ACTION_NAME, redirect_action.CONTROLLER_NAME)); } } else { SET_ROLE role = db.SET_ROLE.Where(r => r.USER_TYPE_NO == user.USER_TYPE_NO).FirstOrDefault(); decimal?ROLE_NO = null; if (role != null) { ROLE_NO = role.ROLE_NO; Session["ROLE_NO"] = role.ROLE_NO; } //ROLE_NO = decimal.Parse(Session["ROLE_NO"].ToString()); List <SET_ROLE_ACTION> per_list = new List <SET_ROLE_ACTION>(); if (ROLE_NO.HasValue) { per_list = db.SET_ROLE_ACTION.Include(a => a.GEN_CONTROLLER_ACTION) .Where(a => (a.ROLE_NO == ROLE_NO.Value) && (a.IS_ACTIVE == 1)) .ToList(); List <GEN_CONTROLLER_ACTION> menu_list = (from c in per_list where (c.GEN_CONTROLLER_ACTION.IS_MENU == 1 && c.GEN_CONTROLLER_ACTION.IS_ACTIVE == 1 ) orderby c.GEN_CONTROLLER_ACTION.SL_NUM select c.GEN_CONTROLLER_ACTION).ToList(); Session["sess_MENU_LIST"] = menu_list; Session["sess_PERMISSION_LIST"] = per_list; if (menu_list != null) { GEN_CONTROLLER_ACTION redirect_action = menu_list.First(); return(RedirectToAction(redirect_action.ACTION_NAME, redirect_action.CONTROLLER_NAME)); } } } } return(View()); }
public JsonResult Login(SEC_USERS sec_users) { //MobileLogger.logDefault( "called", "test"); //return Request.CreateResponse(HttpStatusCode.OK, sec_users); bool is_success = false; string msg = @""; decimal login_msg_type = (decimal)LOGIN_MSG_TYPE.NOTHING; string down_link = string.Empty; string version_number = string.Empty; decimal? USER_NO = null; decimal? ENTRY_USER_NO = null; decimal? ZM_USER_NO = null; decimal? AGENT_USER_NO = null; string SESSION_ID = string.Empty; DateTime?SERVER_TIME = null; decimal? LAST_PK_VAL = null; string APP_VERSION = string.Empty; try { var gen_app_version = db.GEN_APP_VERSION.Where(a => a.IS_CURR_VER == 1).FirstOrDefault(); if (gen_app_version != null) { APP_VERSION = gen_app_version.APP_VERSION; } if (string.IsNullOrEmpty(sec_users.APP_VERSION) || string.IsNullOrWhiteSpace(sec_users.APP_VERSION)) { msg = "APP VERSION is required"; login_msg_type = (decimal)LOGIN_MSG_TYPE.INVALID_APP_VERSION; //var result = new { @SESSION_ID = "", @SERVER_TIME = "", @msg = msg }; //return Json(result, JsonRequestBehavior.AllowGet); } else { if (APP_VERSION.Trim().ToUpper() != sec_users.APP_VERSION.Trim().ToUpper()) { msg = @"Application Version Mismatch, Please download the updated version from https://dl.dropboxusercontent.com/u/67899212/Omicon.apk"; login_msg_type = (decimal)LOGIN_MSG_TYPE.INVALID_APP_VERSION; down_link = gen_app_version.DOWN_LINK; version_number = gen_app_version.APP_VERSION; //var result = new { @SESSION_ID = "", @SERVER_TIME = "", @msg = msg }; //return Json(result, JsonRequestBehavior.AllowGet); } else { var res_obj = db.SEC_USERS_LOGIN(sec_users.USER_NAME, sec_users.USER_PWD, null).FirstOrDefault(); if (res_obj != null) { if (res_obj.USER_NO > 0) { // Session["sess_sec_users"] = res_obj; Session["sess_USER_NO"] = res_obj.USER_NO; USER_NO = res_obj.USER_NO; SERVER_TIME = res_obj.SERVER_TIME; if (res_obj.USER_TYPE_NO == (decimal)UserType.Agents) { Session["sess_entry_user_no"] = res_obj.USER_NO; Session["sess_zm_user_no"] = res_obj.USER_PARENT_NO; Session["sess_agent_user_no"] = res_obj.USER_NO; ENTRY_USER_NO = res_obj.USER_NO; ZM_USER_NO = res_obj.USER_PARENT_NO; AGENT_USER_NO = res_obj.USER_NO; } else { Session["sess_entry_user_no"] = res_obj.USER_NO; Session["sess_zm_user_no"] = res_obj.USER_NO; Session["sess_agent_user_no"] = null; ENTRY_USER_NO = res_obj.USER_NO; ZM_USER_NO = res_obj.USER_PARENT_NO; AGENT_USER_NO = res_obj.USER_NO; } string sess_id = Session.SessionID; string ip_addr = CustomValidator.GetRequestIpAddress(); string device_id = CustomValidator.GetDeviceId(); string login_mobile = sec_users.USER_MOBILE; string ws_id = CustomValidator.GetWebServerId(); string app_version = sec_users.APP_VERSION; SESSION_ID = sess_id; decimal LOGON_NO = db.SEC_USER_LOGONS_INSERT(res_obj.USER_NO, ip_addr, device_id, null, null, null, (decimal)ApproveType.Approved, null, null, sess_id, login_mobile, ws_id, app_version, login_mobile).First().Value; Session["sess_LOGON_NO"] = LOGON_NO; LAST_PK_VAL = db.TRN_OFFLINE_LAST_PK_GET(res_obj.USER_NO).FirstOrDefault(); is_success = true; if (sec_users.USER_NAME == "testuser") { MobileLogger.logDefault("found him testuser " + USER_NO + " msg " + is_success.ToString(), "test"); } //var result = new { @SESSION_ID = sess_id, @SERVER_TIME = res_obj.SERVER_TIME, @msg = "" }; //return Json(result, JsonRequestBehavior.AllowGet); } else { msg = "Invalid Username or password"; login_msg_type = (decimal)LOGIN_MSG_TYPE.INVALID_LOGIN; //var result = new { @SESSION_ID = "", @SERVER_TIME = "", @msg = msg }; //return Json(result, JsonRequestBehavior.AllowGet); } //MobileLogger.logDefault((res_obj.USER_NO == null) ? "NULL user no in Login LN:143 WS_SEC_USERS Controller" : res_obj.USER_NO.ToString(),"username"); } else { msg = "Invalid Username or password"; login_msg_type = (decimal)LOGIN_MSG_TYPE.INVALID_LOGIN; //var result = new { @SESSION_ID = "", @SERVER_TIME = "", @msg = msg }; //return Json(result, JsonRequestBehavior.AllowGet); } } } if (sec_users.USER_NAME == "testuser" && !is_success) { MobileLogger.logDefault(msg, "test"); } var result_object = new { @SESSION_ID = SESSION_ID, @SERVER_TIME = SERVER_TIME, @msg = msg, @is_success = is_success, @USER_NO = USER_NO, @ENTRY_USER_NO = ENTRY_USER_NO, @ZM_USER_NO = ZM_USER_NO, @AGENT_USER_NO = AGENT_USER_NO, @login_msg_type = login_msg_type, @down_link = down_link, @version_number = version_number, @LAST_PK_VAL = LAST_PK_VAL, }; return(Json(result_object, JsonRequestBehavior.AllowGet)); //return null; } catch (Exception ex) { DbErrorTracker db_error = new DbErrorTracker(); db_error.WriteErrorLog(db_error.GetErrorMessage(ex, true), ex, sess_entry_user_name); return(null); } }