コード例 #1
0
        public virtual async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.UserName, Id = UserId.CreateNew().ToString()
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #2
0
        public void serialize_userAdded()
        {
            var evnt = new UserCreated(Guid.NewGuid(), DateTime.Now, UserId.CreateNew(), new UserLoginInfo("prov", "key"), "username", "password");


            var settings = new JsonSerializerSettings
            {
                TypeNameHandling     = TypeNameHandling.None,
                DefaultValueHandling = DefaultValueHandling.Ignore,
                NullValueHandling    = NullValueHandling.Ignore,
                ConstructorHandling  = Newtonsoft.Json.ConstructorHandling.Default,
                //Formatting = Newtonsoft.Json.Formatting.Indented,
                ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver
                {
                    DefaultMembersSearchFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                },
                //ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
            };

            var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(evnt, settings));

            var result = (UserCreated)JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data), typeof(UserCreated));

            Assert.AreEqual(evnt.Id, result.Id);
            Assert.AreEqual(evnt.Timestamp, result.Timestamp);
            Assert.AreEqual(evnt.LoginInfo, result.LoginInfo);
            Assert.AreEqual(evnt.UserId, result.UserId);
        }
コード例 #3
0
ファイル: budget_should.cs プロジェクト: valeriob/MyBudget
        public void be_created()
        {
            var budgetId = BudgetId.Create();
            var ownerId  = UserId.CreateNew();
            var budget   = new Budget();

            budget.Create(budgetId, "name", ownerId, Currencies.Euro().IsoCode);

            var events = budget.GetUncommittedEvents();

            Assert.AreEqual(1, events.Count());
            Assert.IsTrue(events.OfType <BudgetCreated>().Any());
        }
コード例 #4
0
        public virtual async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser()
                {
                    UserName = model.UserName, Id = UserId.CreateNew().ToString()
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }