예제 #1
0
 public ActionResult signin(SigninViewModel model, string ReturnUrl)
 {
     MemberInfoModel memberInfo = new MemberInfoModel();
     if(ModelState.IsValid)
     {
         try
         {
             memberInfo = repository.Signin(model);
         }
         catch(RuleException ex)
         {
             ex.CopyToModelState(ModelState);
         }
     }
     if (ModelState.IsValid && memberInfo.Count < 5)
     {
         var user = string.Format("{0}#{1}#{2}", memberInfo.EmployeeID, memberInfo.Email, memberInfo.Level);
         FormsAuthentication.SetAuthCookie(user, false);
         return RedirectToAction("index", "Employee");
     }
     else if(memberInfo.Count == 5)
     {
         ViewData["errMsg"] = MvcHtmlString.Create("비밀번호 5회 오류입니다. <a href=''>비밀번호 재설정</a>");
     }
     return View();
 }
예제 #2
0
        public MemberInfoModel Signin(SigninViewModel model)
        {
            string txt = null;

            #region Vertification
            var errors = new NameValueCollection();
            errors.Add(GetRuleViolations.checkRequire("Email", "이메일", model.Email));
            errors.Add(GetRuleViolations.checkRequire("Password", "비밀번호", model.Password));
            if (errors.Count > 0) throw new RuleException(errors);
            #endregion

            using (SqlConnection connection = new SqlConnection(NihDbConnectionString.Generate))
            {
                SqlCommand command = new SqlCommand("Signin", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Add("@Email", SqlDbType.VarChar, 200).Value = model.Email;
                command.Parameters.Add("@Password", SqlDbType.Char, 56).Value = GetHMAC.Get(model.Password);

                try
                {
                    connection.Open();
                    txt = command.ExecuteScalar().ToString();
                }
                catch(Exception ex)
                {
                    errors.Add("", ex.Message);
                    throw new RuleException(errors);
                }
                finally
                {
                    connection.Close();
                }
            }

            #region Vertification
            if(txt == "")
            {
                errors.Add("", string.Format("{0}회원정보가 존재하지 않습니다.", txt));
                throw new RuleException(errors);
            }
            #endregion

            char p = '#';

            string[] info = txt.Split(p);
            var memberInfo = new MemberInfoModel { EmployeeID = info[0], Email = info[1], Level = info[2], Count = Convert.ToInt32(info[3]) };

            #region Vertification
            if(memberInfo.Count > 0 && memberInfo.Count < 5)
            {
                errors.Add("", string.Format("비밀번호 {0}회 오류입니다. 5회이상 오류 시 인증이 필요합니다.", memberInfo.Count));
            }

            if (errors.Count > 0) throw new RuleException(errors);
            #endregion

            return memberInfo;
        }