public User Handle(int? accountId, AccountCreateModel form) { if (AccountReceivedEmailInvitation(accountId)) { //TODO: ¿Si el usuario no existe, significa que la url fue manipulada? //TODO: ¿Si la cuenta ya tiene los datos completos? var user = Current.Connection.Get<User>(accountId); if (form.Email != user.Email && ExistsAccountWithSameEmail(form.Email)) throw new ValidationException("Email", "Your Email already exists"); if (ExistsAccountWithSameUserName(form.UserName)) throw new ValidationException("UserName", "Your UserName already exists"); user.Map(form, new[] { "Email" }); //user.DoesNotNeedToConfirmEmail(); Update(user); return user; } else { if (ExistsAccountWithSameEmail(form.Email)) throw new ValidationException("Email", "Your Email already exists"); if (ExistsAccountWithSameUserName(form.UserName)) throw new ValidationException("UserName", "Your UserName already exists"); var owner = User.CreateOwner(form.FirstName, form.LastName, form.UserName, form.Password, form.Email, null, null, null, null, 0, 0, null, 0, System.DateTime.Now, 1, 0, null, false, false, true, false, false); Save(owner); //SendConfirmationEmail(owner); return owner; } }
public ActionResult Create(int? invitationId, AccountCreateModel form) { User user = null; if (ModelState.IsValid) { try { user = new AccountCreateHandler().Handle(invitationId, form); var path = "~/Swisskip/" + form.UserName; if (!Directory.Exists(Server.MapPath(path))) Directory.CreateDirectory(Server.MapPath(path)); Session["path"] = path; Session["user"] = user; //Creating a default photo string newFile = Server.MapPath("~/Content/images/") + form.UserName + ".jpg"; if (!System.IO.File.Exists(newFile)) System.IO.File.Copy(Server.MapPath("~/Content/images/unknown.jpg"), Server.MapPath("~/Content/images/") + form.UserName + ".jpg"); } catch (ValidationException e) { ModelState.AddModelError(e.Key, e.Message); } } if (!ModelState.IsValid) return this.View(); if (invitationId.HasValue) { AuthenticationService.SignIn(user); //return new RedirectToAccountType(user); return RedirectToAction("SecretInfo"); } return RedirectToAction("ConfirmYourEmailAddress"); }