public MembershipCreateStatus CreateUser(UserData userInfo)
        {
            if (String.IsNullOrEmpty(userInfo.Email)) throw new ArgumentException("Value cannot be null or empty.", "Email");
            if (String.IsNullOrEmpty(userInfo.Password)) throw new ArgumentException("Value cannot be null or empty.", "Password");
            if (String.IsNullOrEmpty(userInfo.FirstName)) throw new ArgumentException("Value cannot be null or empty.", "First Name");
            if (String.IsNullOrEmpty(userInfo.LastName)) throw new ArgumentException("Value cannot be null or empty.", "First Name");

            if (String.IsNullOrEmpty(userInfo.Role))
                userInfo.Role = "Guest";

            userInfo.LastLogin = new DateTime(1900, 1, 1);
            userInfo.Email = userInfo.Email.ToLower();

            var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));
            var context = account.CreateCloudTableClient().GetDataServiceContext();

            var currentUser = context.CreateQuery<UserData>("Users")
                        .Where(user => user.PartitionKey == "wedding" &&
                                                     user.Email == userInfo.Email)
                        .FirstOrDefault();

            if (currentUser != null)
                return MembershipCreateStatus.DuplicateUserName;

            context.AddObject("Users", userInfo);
            context.SaveChangesWithRetries();

            return MembershipCreateStatus.Success;
        }
Example #2
0
        public override bool OnStart()
        {
            var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));

            var wishesCreated = account.CreateCloudTableClient().CreateTableIfNotExist("Wishes");
            var usersCreated = account.CreateCloudTableClient().CreateTableIfNotExist("Users");
            var newsCreated = account.CreateCloudTableClient().CreateTableIfNotExist("News");

            var context = account.CreateCloudTableClient().GetDataServiceContext();

            if (usersCreated)
            {
                var admin = new UserData
                {
                    Email = RoleEnvironment.GetConfigurationSettingValue("AdminEmail"),
                    FirstName = RoleEnvironment.GetConfigurationSettingValue("AdminFirstName"),
                    LastName = RoleEnvironment.GetConfigurationSettingValue("AdminLastName"),
                    Password = RoleEnvironment.GetConfigurationSettingValue("AdminPassword"),
                    LastLogin = new DateTime(1900,1,1),
                    Role = "Administrator"
                };
                context.AddObject("Users", admin);
                context.SaveChangesWithRetries();
            }
            return base.OnStart();
        }
Example #3
0
 public ActionResult EditUser(UserData userData)
 {
     if (ModelState.IsValid)
     {
         var createStatus = this.MembershipService.EditUser(userData);
         if (createStatus == MembershipCreateStatus.Success)
         {
             return RedirectToAction("Index", "Home");
         }
         else
         {
             ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
         }
     }
     return View(userData);
 }
Example #4
0
        public ActionResult CreateUser(UserData userData)
        {
            if (ModelState.IsValid)
            {
                var createStatus = this.MembershipService.CreateUser(userData);
                if (createStatus == MembershipCreateStatus.Success)
                {
                    string body = string.Format("{0} buen dia!!, <br/> Tu cuenta para accesar al sitio de Martha & Ivan Wedding " +
                                            "<a ref='http://marthaeivan.cloudapp.net'>http://marthaeivan.cloudapp.net</a> ha sido creada" +
                                            "<br/><br/>usuario:  {1}<br/>password:  {2}<br/><br/>" +
                                            "Tambien puedes entrar usando tu cuenta de facebook siempre y cuando el correo coincida."
                                            , userData.FirstName, userData.Email, userData.Password);
                    GmailService.Send(userData.Email, userData.Email, "Se ha creado tu cuenta :)", body);

                    return RedirectToAction("CreateUser");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            return View(userData);
        }
        public MembershipCreateStatus EditUser(UserData userInfo)
        {
            if (String.IsNullOrEmpty(userInfo.Password)) throw new ArgumentException("Value cannot be null or empty.", "Password");
            if (String.IsNullOrEmpty(userInfo.FirstName)) throw new ArgumentException("Value cannot be null or empty.", "First Name");
            if (String.IsNullOrEmpty(userInfo.LastName)) throw new ArgumentException("Value cannot be null or empty.", "First Name");

            var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));
            var context = account.CreateCloudTableClient().GetDataServiceContext();

            var currentUser = context.CreateQuery<UserData>("Users")
                        .Where(user => user.PartitionKey == "wedding" &&
                                                     user.Email == userInfo.Email)
                        .FirstOrDefault();

            if (currentUser == null)
                return MembershipCreateStatus.InvalidUserName;

            currentUser.FirstName = userInfo.FirstName;
            currentUser.LastName = userInfo.LastName;
            currentUser.Password = userInfo.Password;

            context.UpdateObject(currentUser);
            context.SaveChangesWithRetries();

            return MembershipCreateStatus.Success;
        }
        public void UpdateLastLogin(string email)
        {
            var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));
            var context = account.CreateCloudTableClient().GetDataServiceContext();

            var user = context.CreateQuery<UserData>("Users")
                       .Where(u => u.PartitionKey == "wedding" &&
                                                    u.Email == email)
                       .FirstOrDefault();
            if (user != null)
            {
                user.LastLogin = DateTime.Now;
                context.UpdateObject(user);
                context.SaveChangesWithRetries();

                this.User = user;
            }
        }
Example #7
0
 public ActionResult UpdateUser(UserData userData)
 {
     return EditUser(userData);
 }