예제 #1
0
 public ActionResult Index(Account model)
 {
     if (ModelState.IsValid)
     {
         var dao    = new AccountDao();
         var result = dao.Login(model.Username, Encryptor.MD5Hash(model.Password));
         if (result == 1)
         {
             var user        = dao.GetById(model.Username);
             var userSession = new UserLogin();
             userSession.Email    = user.Email;
             userSession.Username = user.Username;
             Session.Add(CommonConstants.USER_SESSION, userSession);
             return(Redirect("/"));
         }
         else if (result == 0)
         {
             ModelState.AddModelError("", "Not existing username");
         }
         else if (result == -1)
         {
             ModelState.AddModelError("", "Incorrect password");
         }
     }
     return(View(model));
 }
예제 #2
0
        public Result <string, Account> GetById(long id)
        {
            try
            {
                _logger.LogInformation("Getting account using id: {0}", id);
                var accountHolder = _accountDao.GetById(id);

                if (accountHolder == null)
                {
                    return(Result <string, Account> .ForFailure("Account not found"));
                }

                return(Result <string, Account> .ForSuccess(accountHolder));
            }
            catch (Exception ex)
            {
                _logger.LogError("Can't get account by id: {0}", id, ex);
                return(Result <string, Account> .ForFailure("Can't get account"));
            }
        }
예제 #3
0
        public ActionResult SignUp(Account model)
        {
            if (ModelState.IsValid)
            {
                var dao = new AccountDao();
                if (dao.CheckUserName(model.Username))
                {
                    ModelState.AddModelError("", "Already taken");
                }
                else if (dao.CheckEmail(model.Email))
                {
                    ModelState.AddModelError("", "This email belongs to another account");
                }
                else
                {
                    var user = new Account();
                    user.Username = model.Username;
                    user.Password = Encryptor.MD5Hash(model.Password);
                    user.Email    = model.Email;

                    var result = dao.Insert(user);
                    if (result != null)
                    {
                        ViewBag.Success = "Đăng ký thành công";
                        model           = new Account();
                        var userd       = dao.GetById(model.Username);
                        var userSession = new UserLogin();
                        userSession.Email    = user.Email;
                        userSession.Username = user.Username;
                        Session.Add(CommonConstants.USER_SESSION, userSession);
                        return(Redirect("/"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Đăng ký không thành công.");
                    }
                }
            }
            return(View(model));
        }
예제 #4
0
        private bool AccountExists(long id)
        {
            var account = _accountDao.GetById(id);

            return(account != null ? true : false);
        }