コード例 #1
0
        public IActionResult SurveyQuestion([Bind] Ad_Login ad)
        {
            int res = LoginCheck(ad);

            if (res == 1)
            {
                /*TempData["msg"] = "Login Successfully.";*/
                return(View("GetDetails"));
            }
            else
            {
                TempData["msg"] = "Username or Password is wrong! Please login again later.";
                return(View("Index"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> IndexAsync(Login ob)
        {
            if (ModelState.IsValid)
            {
                Ad_Login obj1 = _db.Admins_Login.Find(ob.Id);
                if (obj1 != null)
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.NameIdentifier, obj1.Id.ToString()),
                        new Claim(ClaimTypes.Role, "Admin"),
                    };

                    var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    //var authProperties = new AuthenticationProperties();
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                                  new ClaimsPrincipal(claimsIdentity));

                    return(RedirectToAction("AllEmployees"));
                }
                Employee_Login obj2 = _db.Employees_Login.Find(ob.Id);
                if (obj2 != null)
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.NameIdentifier, obj2.Id.ToString()),
                        new Claim(ClaimTypes.Role, "Employee"),
                    };

                    var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    var authProperties = new AuthenticationProperties();
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                                  new ClaimsPrincipal(claimsIdentity),
                                                  authProperties);

                    if ((_db.Employees.FirstOrDefault(u => u.EmployeeId == ob.Id)) != null)
                    {
                        return(RedirectToAction("Details2", new { id = ob.Id }));
                    }
                    return(RedirectToAction("Create"));
                }
                return(NotFound());
            }
            return(View(ob));
        }
コード例 #3
0
        public int LoginCheck(Ad_Login ad)
        {
            SqlConnection sqlconn = new SqlConnection(GetConnection().GetSection("ConnectionStrings").GetSection("DefaultConnection").Value);

            SqlCommand com = new SqlCommand("Srv_Login", sqlconn);

            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.AddWithValue("@UserName", ad.UserName);
            com.Parameters.AddWithValue("@PassWord", ad.PassWord);
            SqlParameter oblogin = new SqlParameter();

            oblogin.ParameterName = "@IsValid";
            oblogin.SqlDbType     = SqlDbType.Bit;
            oblogin.Direction     = ParameterDirection.Output;
            com.Parameters.Add(oblogin);
            sqlconn.Open();
            com.ExecuteNonQuery();
            int res = Convert.ToInt32(oblogin.Value);

            sqlconn.Close();
            return(res);
        }