コード例 #1
0
ファイル: UsuarioController.cs プロジェクト: ericoloewe/TimeS
 public IHttpActionResult PostUsuario(RegisterViewModel usuario)
 {
     var novoUsuario = _usuarioBll.AddUsuario(usuario);
     if (novoUsuario == null)
         return NotFound();
     return Ok(novoUsuario);
 }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: ericoloewe/TimeS
        public async Task<ActionResult> Register(RegisterViewModel model, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var user = new Usuario() { UserName = model.Email, Email = model.Email, Nome = model.Nome };
                if (image != null)
                {
                    user.ImageMimeType = image.ContentType;
                    user.Foto = new byte[image.ContentLength];
                    image.InputStream.Read(user.Foto, 0, image.ContentLength);
                }
                var result = await UserManager.CreateAsync(user, model.Password);
                UserManager.AddToRole(user.Id, "Comum");
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToLocal("/");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }