Exemplo n.º 1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else if (Membership.GetUser(model.UserName) != null)
            {
                ModelState.AddModelError("UserName", "A user with that name already exists");
                return(View(model));
            }
            else if (Membership.FindUsersByEmail(model.Email).Count > 0)
            {
                var user = Membership.FindUsersByEmail(model.Email);
                ModelState.AddModelError("Email", "A user with that e-mail already exists");
                return(View(model));
            }

            Membership.CreateUser(model.UserName, model.Password, model.Email);
            Roles.AddUserToRole(model.UserName, "Users");

            FormsAuthentication.SetAuthCookie(model.UserName, true);

            repository.AddStatistic(new CreateStatisticModel
            {
                Type      = (int)StatisticsHelper.StatisticTypes.Register,
                Time      = DateTime.Now,
                IPAddress = Request.UserHostAddress,
                UserName  = model.UserName,
                Email     = model.Email
            });

            return(RedirectToAction("Index", "Profile"));
        }
Exemplo n.º 2
0
        public ActionResult AddTrackedData(CreateTrackedDataViewModel model)
        {
            repository.AddTrackedData(model);

            repository.AddStatistic(new CreateStatisticModel
            {
                Type      = (int)StatisticsHelper.StatisticTypes.AddedCat,
                Time      = DateTime.Now,
                IPAddress = Request.UserHostAddress,
                UserName  = User.Identity.Name,
                Email     = Membership.GetUser(User.Identity.Name).Email
            });

            return(RedirectToAction("Index", "Profile"));
        }
Exemplo n.º 3
0
        // GET: Index
        public ActionResult Index()
        {
            string address = Request.UserHostAddress;
            int    type    = repository.CheckIP(address) ? (int)StatisticsHelper.StatisticTypes.Visitor : (int)StatisticsHelper.StatisticTypes.UniqueVisitor;

            string userName = String.IsNullOrEmpty(User.Identity.Name) ? null : User.Identity.Name;
            string email    = userName == null ? null : Membership.GetUser(User.Identity.Name).Email;

            repository.AddStatistic(new CreateStatisticModel
            {
                Type      = type,
                Time      = DateTime.Now,
                IPAddress = address,
                UserName  = userName,
                Email     = email,
            });

            return(View());
        }