Esempio n. 1
0
        public User Handle3(BasicInfoModel form, BasicInfoModel data)
        {
            User user = this.Find2(data.Email);

            if (user.Banned)
            {
                DateTime fecha = (DateTime)user.ModifiedDate;
                if (System.DateTime.Now > fecha.AddDays(1))
                {
                    user.Banned = false;
                    user.ModifiedDate = System.DateTime.Now;
                    user.Tried = 0;
                    Current.Connection.Update(user);
                }
                else
                    return user;
            }

            if (data.TokenNumber.ToString() != form.TokenNumberNew)
            {
                data.Count = data.Count + 1;
                if (data.Count >= 3)
                {
                    user.Banned = true;
                    user.ModifiedDate = System.DateTime.Now;
                    Current.Connection.Update(user);
                    throw new ValidationException("Blocked Token");
                }
                throw new ValidationException("Invalid Token");
            }
            else
            {
                user.Banned = false;
                user.ModifiedDate = System.DateTime.Now;
                user.Tried = 0;
                Current.Connection.Update(user);
                return user;
            }
        }
        public ActionResult Confirm(int? userId, BasicInfoModel form)
        {
            BasicInfoModel data = (BasicInfoModel)Session["Trying"];
            User user = null;
            if (ModelState.IsValid)
            {
                try
                {
                    user = new SignInHandler().Handle3(form, data);
                    if (user.Banned)
                        return RedirectToAction("BannedAccount");
                }
                catch (ValidationException e)
                {
                    ModelState.AddModelError(e.Key, e.Message);
                }
            }

            if (!ModelState.IsValid)
            {
                Session["Trying"] = data;
                Session["AccessDenied"] = 1;
                return this.View(data);
            }

            Session["AccessDenied"] = 0;
            if (!user.IsOwner)
                return new RedirectToAccountType(user);

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