public int isUserAvailable(Loginmodel Objlogin) { //user avaliable return user id // bool isusermatch = false; try { using (var entity = new HapinessSurveyEntities()) { // var obj = from u in entity.UserTbls where u.user_mail = Objlogin.user_mail && u.user_Pass = Objlogin.user_pass select u. var obj = entity.UserTbls.Where(a => a.user_mail.Equals(Objlogin.user_mail) && a.user_Pass.Equals(Objlogin.user_pass)).FirstOrDefault(); if (obj != null) { isuservalue = obj.user_id; // isusermatch = true; } else { isuservalue = 0; // isusermatch = false; } } } catch (Exception ex) { } // return isusermatch; return(isuservalue); }
/// <summary> /// Checks wether the login info matches the given credentials /// </summary> /// <param name="loginModel"></param> public static bool Authenticate(Loginmodel loginModel) { try { // 01. Check if the user exists var _user = Get(loginModel.CredentialName); if (_user == null) { throw new UserNotFoundException(loginModel.CredentialName); } var encrypted = SecurityExtensions.Encrypt(loginModel.Password + _user.Salt); if (_user.Password == encrypted) { DAL_Users.SetAuthenticatedUser(_user.Id); return(true); } else { return(false); } } catch (Exception) { throw; } }
public ActionResult Login(Loginmodel objlogin) { if (ModelState.IsValid) { ILogin _login = new Login(); Session["isuserId"] = _login.isUserAvailable(objlogin); //user id from login interface Session["RoleID"] = _login.isUserRoleID(objlogin); //role id from login interface return(RedirectToAction("Dashboard")); } return(View()); }
public ActionResult Dashboard() { if (ModelState.IsValid) { int id = Convert.ToInt32(Session["isuserId"]); ILogin _ud = new Login(); Loginmodel objlogin = new Loginmodel(); UserDisplayViewModel model = new UserDisplayViewModel(); model = _ud.isdetail(id); TempData["dep_name"] = model.dep_name; TempData["user_name"] = model.user_name; if (Session["isuserId"] != null) { int Roleid = (int)Session["RoleID"]; if (Roleid == 1) { //admin // return RedirectToAction("","") return(View("AdminDashboard")); } else if (Roleid == 2) {//Senior manager return(View("SeniorDashboard")); } else if (Roleid == 3) { //manager return(View("ManagerDashboard")); } else if (Roleid == 4) { //team leader return(View("teamladerDashboard")); } else if (Roleid == 5) { //team mamber return(View("TeammemberDashboard")); } else if (Roleid == 0) { //user.."name" role not define return(RedirectToAction("Login")); } else if (Roleid == 6) { //here also check TL have TM access ? //Roleid 4 and 5 return(View("TMTLDashboard")); } } } return(RedirectToAction("Login")); }
public async Task <IActionResult> Login([FromBody] Loginmodel lm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var res = await _auth.LoginAsync(lm); if (!res.IsAuthenticated) { return(BadRequest(res.Message)); } return(Ok(res)); }
public ActionResult Login(Loginmodel userinfo) { if (ModelState.IsValid) { int userid = Data.loginfo(userinfo.username, userinfo.password); if (userid != 0) { Session["id"] = userid; return(Redirect("/Admin/Dashboard")); } else { ViewBag.logmsg = "Wrong Username or password"; return(View()); } } return(View()); }
public string Login([FromBody] Loginmodel model) { if (model.LoginUserName == "DuPontTest" && model.Password.Contains("dupont123")) { System.Web.HttpContext.Current.Application["num"] = 1; HttpCookie cookie = new HttpCookie("Login"); cookie.Values["name"] = model.LoginUserName; cookie.Values["password"] = model.LoginUserName; cookie.Expires = DateTime.Now.AddDays(1); HttpContext.Current.Response.Cookies.Add(cookie); //设置缓存时间,10分钟 double Seconds = 10; System.Web.HttpContext.Current.Session["user"] = model.LoginUserName; System.Web.HttpContext.Current.Cache.Insert("user", model.LoginUserName, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(Seconds)); return("ok"); } else { return("on"); } }
public async Task <IActionResult> Login([FromBody] Loginmodel model) { var rqf = Request.HttpContext.Features.Get <IRequestCultureFeature>(); model.Lang = rqf.RequestCulture.Culture.ToString().Substring(0, 2); LoginResponse r = new LoginResponse(); if (ModelState.IsValid) { r = await _authService.Login(model.Email, model.Password, model.Lang); return(Ok(r)); } else { r.resultSituation = new SimpleResponse(); r.resultSituation.ErrorCode = 1; r.resultSituation.Result = _localizer["ModelInValid"]; return(Ok(r)); } }
public async Task <Authmodel> LoginAsync(Loginmodel lm) { var model = new Authmodel(); var user = await _user.FindByNameAsync(lm.username); if (user is null || !await _user.CheckPasswordAsync(user, lm.password)) { model.Message = "Username Or Password inCorrect"; return(model); } var token = await Generatetoken(user); var roles = await _user.GetRolesAsync(user); model.IsAuthenticated = true; model.Username = user.UserName; model.Email = user.Email; model.DeptID = user.DeptId; model.Tokenlife = token.ValidTo; model.Token = new JwtSecurityTokenHandler().WriteToken(token); model.Roles = roles.ToList(); return(model); }
public int isUserRoleID(Loginmodel Objlogin) { //get Roll iD for controller dashboard var role = 0; var roleid = 0; try { using (var entity = new HapinessSurveyEntities()) { teamtbl teamobj = new teamtbl(); role = (int)entity.teamtbls.Where(a => a.user_id.Equals(isuservalue)).LongCount(); if (role == 1) { roleid = entity.teamtbls.Where(a => a.user_id.Equals(isuservalue)).Select(a => a.role_id).FirstOrDefault(); //if assign any one role. } else if (role == 0) { roleid = role; //if not assign any role } else if (role == 2) { //if teamlead and teammember role // var roleid1 = entity.teamtbls.Where(a => a.user_id.Equals(isuservalue)).Select(a => a.role_id).ToList(); // roleid = roleid1.Min(); roleid = 6; // roleid = entity.teamtbls.Where(a => a.user_id.Equals(isuservalue)).Select(a => a.role_id).Min(); } } } catch (Exception ex) { } return(roleid); }
async Task Login() { Isenabled = false; IsRunning = true; try { var client = new HttpClient(); client.BaseAddress = new Uri(Settings.Ngrok + "Users"); User user = new User(); user.Email = email; user.Password = password; String Userdata = JsonConvert.SerializeObject(user); var content = new StringContent(Userdata, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("users/Login", content); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); Loginmodel modeldata = JsonConvert.DeserializeObject <Loginmodel>(result); Settings.GeneralSettings = result; if (modeldata.RoleName == "Patient") { client = new HttpClient(); var uri = new Uri(string.Format(Settings.Ngrok + "patient/GetPatientByUserId/" + modeldata.ID));//+ loginmodel.ID response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { var loginresult = await response.Content.ReadAsStringAsync(); Settings.GeneralSettings = loginresult; await Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new Ambulance.UserViews.UserViews()); } else { DependencyService.Get <Toast>().Show("Faild to connect server"); } } else { var uri = new Uri(string.Format(Settings.Ngrok + "Paramedic/GetParamedicByUserId/" + modeldata.ID)); response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { var paramedicdata = await response.Content.ReadAsStringAsync(); Settings.GeneralSettings = paramedicdata; Paramedicdata paramedic = JsonConvert.DeserializeObject <Paramedicdata>(Settings.GeneralSettings) as Paramedicdata; DependencyService.Get <Toast>().Show("Hello " + paramedic.UserData.Username.ToString()); await Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new Ambulance.Paramedic.Views.EnterCarNo()); return; } else { DependencyService.Get <Toast>().Show("Faild to connect server"); } } } else { DependencyService.Get <Toast>().Show("Invaild Email or Password"); Isenabled = true; IsRunning = false; return; } } catch (Exception x) { Isenabled = true; IsRunning = false; DependencyService.Get <Toast>().Show("No internet connection"); } }
public ActionResult Index(Loginmodel model) { using (var db = new Data_MassageEntities1()) { var dao = new UserDao(); //var result = new AccountModel().Login(model.UserName, model.Password);new EmployeeDAO().MD5Hash(model.Password) var result = dao.login(model.UserName, model.Password); switch (result) { case 1: var user = dao.GetById(model.UserName); var userSesstion = new UserLogin(); Session["userName"] = model.UserName; Session["userId"] = user.Id_User; Session["status_color"] = user.Dark_Light_theme; var mau = ""; var list_color = db.SettingAdmins.Where(x => x.ID_User == user.Id_User).ToArray(); var dangky = db.BDang_Ky.Where(x => x.ID_dang_Ky == 1).ToArray(); var yt = 0; if (dangky[0].Thoi_Gian_Check_Int > 0) { yt = (int)dangky[0].Thoi_Gian_Check_Int; } if (list_color.Any()) { mau = list_color[0].colorbar + "|" + list_color[0].cochu + "|" + list_color[0].fontchu + "|" + list_color[0].mauchu + "|" + list_color[0].maucokhach + "|" + list_color[0].mauonline + "|" + list_color[0].maucho + "|" + yt + "|" + list_color[0].heightContent + "|" + list_color[0].heightRight + "|" + list_color[0].widthContent + "|" + list_color[0].widthRight + "|" + list_color[0].thongbao + "|" + list_color[0].chuy + "|" + list_color[0].maunhanvienonline + "|" + list_color[0].maunhanviencokhach; } Session["chang_color"] = mau; if (db.tbl_CaLamViec.Any()) { var moca = db.tbl_CaLamViec.Where(x => x.Status == 1).ToArray(); if (moca.Any()) { moca = db.tbl_CaLamViec.Where(x => x.Status == 1 && x.Id_nhan == user.Id_User).ToArray(); if (moca.Any()) { Session["status_KA"] = 1; Session["Id_giao_KA"] = moca[0].Id; } else { Session["status_KA"] = 3; Session["Id_giao_KA"] = -1; } } else { var moca1 = db.tbl_CaLamViec.OrderByDescending(x => x.Id).Take(1).ToList(); moca1 = moca1.Where(x => x.Id_nhan == user.Id_User).ToList(); if (moca1.Any()) { Session["status_KA"] = 2; Session["Id_giao_KA"] = 0; } else { Session["status_KA"] = 3; Session["Id_giao_KA"] = -1; } } } else { Session["status_KA"] = 2; Session["Id_giao_KA"] = 0; } Session["setting"] = 0; userSesstion.UserName = user.Name_User; userSesstion.UserID = user.Id_User; Session.Add(CommonConstants.USER_SESSTION, userSesstion); var id_dangnhap = userSesstion.UserID; var id_setting = db.SettingAdmins.Where(x => x.ID_User == id_dangnhap).ToArray(); if (id_setting.Any()) //Any khong hoat hoat dong khi .Tolist(); { var set = id_setting[0].ID_User; if (id_dangnhap == set) { return(RedirectToAction("Home", "AdminHome")); } else { return(RedirectToAction("Setting", "AdminSettingAdmin")); } } else { Session["setting"] = 1; return(RedirectToAction("Setting", "AdminSettingAdmin")); } case 0: ModelState.AddModelError("", "Tai khoan khong ton tai !"); break; case -1: ModelState.AddModelError("", "Tai khoan dang bi khoa !"); break; case -2: ModelState.AddModelError("", "Mat khau sai !"); break; default: ModelState.AddModelError("", "Tên đăng nhập or mật khẩu không đúng !"); break; } return(View(model)); } }