Пример #1
0
        public async Task <IViewComponentResult> InvokeForUserAsync(string siteId, Identity.Models.User user)
        {
            var groups = await _userGroupManager.GetPublicUserGroupsForUserAndSiteAsync(user.Id, siteId, Models.UserGroupType.NotificationGroup);

            var model = new List <UserMembershipViewModel>();

            foreach (var group in groups)
            {
                model.Add(new UserMembershipViewModel()
                {
                    UserGroupId           = group.UserGroupId,
                    UserGroupName         = group.UserGroup.Name,
                    AllowPublicEnrollment = group.UserGroup.AllowPublicEnrollment,
                    AllowEmailMessaging   = group.AllowEmailMessaging,
                    AllowSmsMessaging     = group.AllowSmsMessaging,
                    IsMember = (group.UserId != null)
                });
            }
            model = model.OrderBy(m => m.UserGroupName).ToList();

            ViewData["userId"] = user.Id;
            ViewData["siteId"] = siteId;

            return(View("NotifyMeEditList", model));
        }
Пример #2
0
        /// <summary>
        /// 添加店铺信息信息
        /// </summary>
        /// <param name="inputDtos">要添加的店铺信息DTO信息</param>
        /// <returns>业务操作结果</returns>
        public OperationResult AddGoodsComments(params GoodsCommentInputDto[] inputDtos)
        {
            OperationResult result = GoodsCommentRepository.Insert(inputDtos,
                                                                   dto =>
            {
            },
                                                                   (dto, entity) =>
            {
                if (dto.GoodsId.HasValue && dto.GoodsId.Value > 0)
                {
                    Goods.Models.Goods goods = GoodsRepository.GetByKey(dto.GoodsId.Value);
                    if (goods == null)
                    {
                        throw new Exception("商品不存在");
                    }
                    goods.GoodsComments.Add(entity);
                    entity.Goods = goods;
                }

                if (dto.UserId.HasValue && dto.UserId.Value > 0)
                {
                    Identity.Models.User user = UserRepository.GetByKey(dto.UserId.Value);
                    if (user == null)
                    {
                        throw new Exception("用户不存在");
                    }
                    entity.User = user;
                }

                return(entity);
            });

            return(result);
        }
        public ActionResult Register(Models.RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!model.Accept)
                {
                    ModelState.AddModelError("", "注册账号需要同意《用户协议》");
                }
                var user = new Identity.Models.User
                {
                    UserName = model.UserName,
                    //PhoneNumber = model.PhoneNumber
                };
                var result = UserManager.Create(user, model.Password);
                if (result.Succeeded)
                {
                    SignInManager.SignIn(user);

                    // 有关如何启用帐户确认和密码重置的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkID=320771
                    // 发送包含此链接的电子邮件
                    // 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, "确认你的帐户", "请通过单击 <a href=\"" + callbackUrl + "\">這裏</a>来确认你的帐户");

                    return(RedirectToAction("Login", "Account"));
                }
                AddErrors(result);
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }
        public async Task <ActionResult> ExternalLoginConfirmation(Models.ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // 从外部登录提供程序获取有关用户的信息
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new Identity.Models.User {
                    UserName = model.UserName, Email = model.Email
                };
                var result = await UserManager.Create(user);

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

                    if (result.Succeeded)
                    {
                        await SignInManager.SignIn(user, isPersistent : false, rememberBrowser : false);

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

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Пример #5
0
        public object Post(
            [FromBody] Security.User usuario,
            [FromServices] IMRVFrameworkService frameworkService,
            [FromServices] SigningConfigurations signingConfigurations,
            [FromServices] TokenConfigurations tokenConfigurations)
        {
            var usuarioBase = new Identity.Models.User();

            if (usuario != null && !String.IsNullOrWhiteSpace(usuario.username))
            {
                var task = Task.Run(async() => await frameworkService.ValidarSenha(usuario.username, usuario.password));
                task.Wait();
                usuarioBase = task.Result;
            }

            if (usuarioBase != null && usuarioBase.Login != null)
            {
                ClaimsIdentity identity = new ClaimsIdentity(new List <Claim> {
                    new Claim(ClaimTypes.NameIdentifier, usuarioBase.Login),
                    new Claim(ClaimTypes.Name, usuarioBase.Name),
                    new Claim(ClaimTypes.Email, usuarioBase.Email),
                    new Claim("Perfil", usuarioBase.Profile),
                    new Claim("CodigoPerfil", usuarioBase.ProfileCode.ToString())
                });

                DateTime dataCriacao   = DateTime.Now;
                DateTime dataExpiracao = DateTime.Now;

                switch (tokenConfigurations.ExpirationType)
                {
                case "Seconds":
                    dataExpiracao = dataCriacao + TimeSpan.FromSeconds(tokenConfigurations.Seconds);
                    break;

                case "Minutes":
                    dataExpiracao = dataCriacao + TimeSpan.FromMinutes(tokenConfigurations.Minutes);
                    break;

                case "Days":
                    dataExpiracao = dataCriacao + TimeSpan.FromDays(tokenConfigurations.Days);
                    break;

                default:
                    break;
                }

                var handler       = new JwtSecurityTokenHandler();
                var securityToken = handler.CreateToken(new SecurityTokenDescriptor
                {
                    Issuer             = tokenConfigurations.Issuer,
                    Audience           = tokenConfigurations.Audience,
                    SigningCredentials = signingConfigurations.SigningCredentials,
                    Subject            = identity,
                    NotBefore          = dataCriacao,
                    Expires            = dataExpiracao
                });
                var token = handler.WriteToken(securityToken);



                return(new
                {
                    authenticated = true,
                    accessToken = token,
                    login = usuario.username,
                    firstName = usuarioBase.Name.Split(' ').FirstOrDefault(),
                    usuario = usuarioBase
                });
            }
            else
            {
                return(new
                {
                    authenticated = false,
                    message = "Falha ao autenticar"
                });
            }
        }
Пример #6
0
 private void SignInAsync(Identity.Models.User user, bool isPersistent)
 {
     //AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
     //AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(UserManager));
 }