Ejemplo n.º 1
0
        public ActionResult LogIn(StudentLogInModel model)
        {
            SecurityRepository rep = new SecurityRepository();

            if (ModelState.IsValid)
            {
                LogInRes res = rep.GetStudentLogIn(new CollegeService.Request.LogInReq {
                    DOB      = model.DOB,
                    HSRollNo = model.HSRollNo
                });


                if (res != null)
                {
                    CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel();
                    serializeModel.UserId    = res.StudentID;
                    serializeModel.FirstName = "";
                    serializeModel.LastName  = "";

                    string userData = JsonConvert.SerializeObject(serializeModel);
                    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                        1,
                        DateTime.Now.ToString(),
                        DateTime.Now,
                        DateTime.Now.AddMinutes(15),
                        false, //pass here true, if you want to implement remember me functionality
                        userData);

                    string     encTicket = FormsAuthentication.Encrypt(authTicket);
                    HttpCookie faCookie  = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                    Response.Cookies.Add(faCookie);


                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View());
        }
Ejemplo n.º 2
0
        public LogInRes GetStudentLogIn(LogInReq req)
        {
            var          retValue    = new LogInRes();
            SqlParameter prmHSRollNo = new SqlParameter("@HSRollNo", SqlDbType.VarChar);

            prmHSRollNo.Value = req.HSRollNo;
            SqlParameter prmApplicationID = new SqlParameter("@ApplicationID", SqlDbType.VarChar);

            prmApplicationID.Value = DBNull.Value;
            SqlParameter prmStudentID = new SqlParameter("@StudentID", SqlDbType.Int);

            prmStudentID.Value = DBNull.Value;
            SqlParameter prmCURegNo = new SqlParameter("@CURegNo", SqlDbType.VarChar);

            prmCURegNo.Value = DBNull.Value;
            SqlParameter prmDOB = new SqlParameter("@DOB", SqlDbType.VarChar);

            prmDOB.Value = req.DOB.Date;
            SqlParameter prmType = new SqlParameter("@Type", SqlDbType.Char);

            prmType.Value = "1";

            using (SqlDataReader dr = SqlServerHelper.ExecuteReaderProc("[Student].[upGetLogin]", prmStudentID, prmApplicationID, prmHSRollNo, prmCURegNo, prmDOB, prmType))
            {
                if (dr != null && dr.HasRows)
                {
                    dr.Read();
                    retValue = new LogInRes
                    {
                        StudentID = Convert.ToInt32(dr["StudentID"]),
                        ProgYear  = object.ReferenceEquals(dr["ProgYear"], DBNull.Value) ? string.Empty : Convert.ToString(dr["ProgYear"]),
                    };
                }
            }
            return(retValue);
        }