当前位置: 首页>>代码示例>>C#>>正文


C# IUserService.CreateUser方法代码示例

本文整理汇总了C#中IUserService.CreateUser方法的典型用法代码示例。如果您正苦于以下问题:C# IUserService.CreateUser方法的具体用法?C# IUserService.CreateUser怎么用?C# IUserService.CreateUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUserService的用法示例。


在下文中一共展示了IUserService.CreateUser方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Authenticate

        public async Task<AuthenticationResult> Authenticate(Dictionary<string, string> authenticationCtx, IUserService userService)
        {
            if (authenticationCtx["provider"] != Provider_Name)
            {
                return null;
            }

            string ticket;
            if (!authenticationCtx.TryGetValue("ticket", out ticket) || string.IsNullOrWhiteSpace(ticket))
            {
                return AuthenticationResult.CreateFailure("Steam session ticket must not be empty.", Provider_Name, authenticationCtx);
            }

            var steamId = await _authenticator.AuthenticateUserTicket(ticket);

            if (!steamId.HasValue)
            {
                return AuthenticationResult.CreateFailure("Invalid steam session ticket.", Provider_Name, authenticationCtx);
            }

            var steamIdString = steamId.GetValueOrDefault().ToString();
            var user = await userService.GetUserByClaim(Provider_Name, ClaimPath, steamIdString);

            if (user == null)
            {
                var uid = Provider_Name + "-" + steamIdString;
                user = await userService.CreateUser(uid, new JObject());

                user = await userService.AddAuthentication(user, Provider_Name, JObject.FromObject(new { CLAIMPATH = steamIdString }));
            }

            return AuthenticationResult.CreateSuccess(user, Provider_Name, authenticationCtx);
        }
开发者ID:Falanwe,项目名称:Stormancer-AuthenticationPlugin,代码行数:33,代码来源:SteamAuthenticationProvider.cs

示例2: UserModule

           public UserModule(IUserService userService):base("/users")
           {
               Get["/{id}", true] = async (ctx, cancel) =>
                   {
                       var request = this.Bind<GetUserByIdRequest>();

                       var user = await userService.GetUserById(new GetUserById()
                           {
                               Id = request.Id
                           });
                       return Response.AsJson(user);
                   };

               Post["/", true] = async (ctx, cancel) =>
                   {
                       var request = this.Bind<CreateUserRequest>();

                       var user = await userService.CreateUser(new CreateUser()
                           {
                               HourlyRate = request.HourlyRate,
                               Salary = request.Salary
                           });
                       
                       return Response.AsJson(user);
                   };
           }
开发者ID:EIrwin,项目名称:naylor-api,代码行数:26,代码来源:UserModule.cs

示例3: SaveUserShouldCallRepository

        public void SaveUserShouldCallRepository()
        {
            UserDto userDto = new UserDto();
            m_UserRepositoryMock = new Mock<IUserRepository>();
            m_BetRepositoryMock = new Mock<IBetRepository>();
            m_MatchRepositoryMock = new Mock<IMatchRepository>();
            m_UserService = new UserService(m_UserRepositoryMock.Object, m_BetRepositoryMock.Object, m_MatchRepositoryMock.Object);

            m_UserService.CreateUser(userDto);

            m_UserRepositoryMock.Verify(x => x.PersistUser(It.IsAny<User>()), Times.Once);
        }
开发者ID:PeterParushev,项目名称:BoxingParadise,代码行数:12,代码来源:UserServiceTests.cs

示例4: UserModule

        public UserModule(IUserService service) : base("/api/users")
        {
            Service = service;

            Post["/login"] = p =>
            {
                var model = this.Bind<NewUserModel>();

                var user = Service.CreateUser(model.Name);

                return Negotiate.WithModel(user.ViewModel);
            };
        }
开发者ID:rafazgz,项目名称:BB20151211-NancyFx,代码行数:13,代码来源:UserModule.cs

示例5: UserModule

        public UserModule(IUserService _userService,
            ISiteService _siteService,
            IRoleService _roleService,
            IUserRoleMappingService _userRoleMappingService)
            : base("/user")
        {
            UserValidator uservalidator = new UserValidator();
            Get["/list"] = x =>
            {
                return View["User/List",_userService.GetAllUser()];
            };

            Get["/add"] = x =>
            {
                ViewBag.Errored = false;
                return View["User/Add", new User()];
            };

            Post["/add"] = x =>
            {
                User user = this.Bind<User>();
                ValidationResult results = uservalidator.Validate(user);
                if (!results.IsValid)
                {
                    ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error,"错误信息", results.Errors);
                    ViewBag.Errored = true;
                    return View["User/Add", user];
                }
                if (_userService.CreateUser(user))
                {
                    ViewBag.ErrorMsg = "<strong>OK~</strong>";
                    ViewBag.Errored = true;
                    return View["User/Add", user];
                }

                ViewBag.ErrorMsg = "<strong>出错啦~</strong>";
                ViewBag.Errored = true;
                return View["User/Add", user];
                //return this.Context.GetRedirect("~/user/add?error=true");
                //return View["User/Add"];
            };

            Get["/edit/{id}"] = x =>
            {
                return View["User/Edit", _userService.GetByAutoId((int)x.id)];
            };

            Post["/edit/{id}"] = x =>
            {
                ViewBag.Errored = true;
                var user = this.Bind<User>();
                var model = _userService.GetById(user.ID);
                if (!String.IsNullOrEmpty(user.Password))
                {
                    model.PasswordSalt = PasswordUtil.GenerateSalt();
                    model.Password = PasswordUtil.EncodePassword(user.Password, model.PasswordFormat, model.PasswordSalt);
                    model.passwordConfirm = PasswordUtil.EncodePassword(user.passwordConfirm, model.PasswordFormat, model.PasswordSalt);
                }
                else
                {
                    model.passwordConfirm = model.Password;
                }
                model.PrivateEmail = user.PrivateEmail;
                model.Nickname = user.Nickname;
                model.Gender = user.Gender;
                model.Status = user.Status;
                ValidationResult results = uservalidator.Validate(model);
                if (!results.IsValid)
                {
                    ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors);
                    return View["User/Edit", user];
                }
                if (user.ID == Guid.Empty)
                {
                    return Response.AsRedirect("/user/list");
                }
                if (_userService.ModifyUser(model))
                {
                    ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息", "修改用户信息成功");
                }
                else
                {
                    ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员");
                }
                return View["User/Edit", user];
            };

            Get["/delete/{id}"] = x =>
            {
                var model = _userService.GetByAutoId((int)x.id);
                _userService.DeleteUser(model.ID);
                return Response.AsRedirect("/user/list");
            };

            Get["/editrole"] = x =>
            {
                Guid userId = new Guid(Request.Query.userId);
                dynamic SiteId = null;
                SiteId = !String.IsNullOrEmpty(Request.Query.siteId.ToString()) && Request.Query.siteId != null ? new Guid(Request.Query.siteId) : Guid.Empty;
                var usermodel = _userService.GetById(userId);
//.........这里部分代码省略.........
开发者ID:vvvsrx,项目名称:AUserCenter,代码行数:101,代码来源:UserModule.cs

示例6: UserModule

        public UserModule(IUserService userService, IErrorService error, IPasswordService passwordService, IUserCacheService userCacheService)
            : base("/user")
        {
            Post["/create"] = _ =>
            {
                if (Params.AreMissing("UserName", "Email")) return error.MissingParameters(Response);
                if (userService.GetUserByName(Params.UserName)!=null) return error.UserNameTaken(Response);
                if (!Params.Email.IsEmail()) return error.InvalidParameters(Response);
                var password = userService.CreateUser(Params.UserName, Params.Email);
                return (string.IsNullOrWhiteSpace(password)) ? error.InvalidParameters(Response) : Response.AsJson(new { Password = password });
            };

            Post["/validate"] = _ =>
            {
                if (Params.AreMissing("UserName", "Password")) return error.MissingParameters(Response);
                var user = userService.GetUserByName(Params.UserName);
                if (user == null || !passwordService.IsPasswordValid(user, Params.Password)) return error.NoUserForCredentials(Response);
                var key = userCacheService.Add(user);
                return (key == null) ? error.InvalidParameters(Response) : Response.AsJson(new { ThumbKey = key });
            };

            Post["/get"] = _ =>
            {
                if (Params.AreMissing("ThumbKey")) return error.MissingParameters(Response);
                if (!Params.ThumbKey.IsGuid()) return error.InvalidParameters(Response);
                var user = userCacheService.GetUser(Params.ThumbKey);
                return (user == null) ? error.NoUserForThumbkey(Response) : Response.AsJson(new { User = new { Id = user.Id, UserName = user.UserName, Email = user.Email } });
            };

            Post["/validate/thumbkey"] = _ =>
            {
                if (Params.AreMissing("ThumbKey")) return error.MissingParameters(Response);
                if (!Params.ThumbKey.IsGuid()) return error.InvalidParameters(Response);
                var isValid = userCacheService.Validate(Params.ThumbKey);
                return !isValid ? error.NoUserForThumbkey(Response) : HttpStatusCode.OK;
            };

            Post["/validate/name"] = _ =>
            {
                if (Params.AreMissing("UserName")) return error.MissingParameters(Response);
                var isValid = userService.GetUserByName(Params.UserName)==null;
                return !isValid ? error.UserNameTaken(Response) : HttpStatusCode.OK;
            };

            Post["/reset/password"] = _ =>
            {
                if (Params.AreMissing("UserName", "Password")) return error.MissingParameters(Response);
                var user = userService.GetUserByName(Params.UserName);
                if (user == null || !passwordService.IsPasswordValid(user, Params.Password)) return error.NoUserForCredentials(Response);
                var password = userService.ResetPassword(user);
                return (password == null) ? error.InvalidParameters(Response) : Response.AsJson(new { Password = password });
            };

            Post["/forgot-password/request"] = _ =>
            {
                if (Params.AreMissing("UserName", "Email")) return error.MissingParameters(Response);
                if (!Params.Email.IsEmail()) return error.InvalidParameters(Response);
                var user = userService.GetUserByName(Params.UserName);
                if (user == null) return error.NoUserForCredentials(Response);
                if (user.Email != Params.Email) return error.NoUserForEmail(Response);
                var token = userService.ForgotPasswordRequest(user);
                return (token == null) ? error.InvalidParameters(Response) : Response.AsJson(new { Token = token });
            };

            Post["/forgot-password/reset"] = _ =>
            {
                if (Params.AreMissing("UserName", "Token")) return error.MissingParameters(Response);
                if (!Params.Token.IsGuid()) return error.InvalidParameters(Response);
                var user = userService.GetUserByName(Params.UserName);
                if (user == null || !passwordService.IsForgotPasswordTokenValid(user, Params.Token)) return error.InvalidForgotPasswordToken(Response);
                var password = userService.ForgotPasswordReset(user);
                return (password == null) ? error.InvalidParameters(Response) : Response.AsJson(new { Password = password });
            };

            Post["/logout"] = _ =>
            {
                if (Params.AreMissing("ThumbKey")) return error.MissingParameters(Response);
                if (!Params.ThumbKey.IsGuid()) return error.InvalidParameters(Response);
                var success = userCacheService.Remove(Params.ThumbKey);
                return !success ? error.NoUserForThumbkey(Response) : HttpStatusCode.OK;
            };
        }
开发者ID:biofractal,项目名称:ThumbsUp,代码行数:82,代码来源:UserModule.cs


注:本文中的IUserService.CreateUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。