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


C# UserRepository.GetByEmail方法代码示例

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


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

示例1: Signin

        public async Task<dynamic> Signin([FromBody] JToken jsonbody)
        {
            if(jsonbody == null || jsonbody.Type != JTokenType.Object)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data."));

            //check data
            var email = jsonbody.SelectToken("email");
            if (email == null || string.IsNullOrWhiteSpace(email.ToString()))
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "email is missed."));

            var password = jsonbody.SelectToken("password");
            if (password == null || string.IsNullOrWhiteSpace(password.ToString()))
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "password is missed."));

            //check if user exists or not
            var userRepo = new UserRepository();
            var userEntity = await userRepo.GetByEmail(email.ToString());
            if(userEntity == null)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid email."));

            if (Encryptor.GetInstance().Decrypt(userEntity.Password) != password.ToString())
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid password."));

            //return user token
            return Ok(new
                {
                    id = userEntity.ID,
                    email = email.ToString(),
                    displayname = userEntity.DisplayName,
                    createdat = userEntity.CreatedAt.ToString("o"),
                    options = userEntity.Options,
                    tag = userEntity.Tag
                });
        }
开发者ID:pdlg-spotlight,项目名称:lambda-architecture,代码行数:34,代码来源:AccountController.cs

示例2: TestGetByEmail

        public void TestGetByEmail()
        {
            try
            {
                const string email = "[email protected]";
                var userRepo = new UserRepository();
                var user = userRepo.GetByEmail(email);
                user.Wait();

                Assert.IsNotNull(user.Result);
                Assert.IsNotNull(user.Result.Emails);
                Assert.IsTrue(user.Result.Emails.Contains(email));
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
开发者ID:pdlg-spotlight,项目名称:lambda-architecture,代码行数:18,代码来源:TestUserRepository.cs

示例3: IsAuthorized

        public override bool IsAuthorized(IAuthSession session, IOAuthTokens tokens, Auth request = null)
        {
            if (tokens != null && !string.IsNullOrEmpty(tokens.Email))
            {
                var repository = new UserRepository();
                var user = repository.GetByEmail(tokens.Email);
                if (user == null)
                {
                    throw new InvalidOperationException("You are not a registered user!");
                    return false;
                }
            }
            if (request != null)
            {
                if (!LoginMatchesSession(session, request.UserName)) return false;
            }

            // For OpenId, AccessTokenSecret is null/empty, but UserId is populated w/ authenticated url from openId providers
            return tokens != null && !string.IsNullOrEmpty(tokens.UserId);
        }
开发者ID:WimAtIHomer,项目名称:Clio,代码行数:20,代码来源:ClioAuthProvider.cs

示例4: RestorePassword

        public ActionResult RestorePassword(RestoreUserPasswordModel restorePassword)
        {
            if ( ModelState.IsValid )
            {
                UserRepository users = new UserRepository();
                UserModel user = (users.GetByUsername( restorePassword.Account ) ?? users.GetByEmail( restorePassword.Account ));
                if ( user == null )
                {
                    throw new Exception( string.Format(
                        "Username or e-mail address '{0}' not found - it should be already validated!", restorePassword.Account ) );
                }

                string activationCode = (new Random().Next( 1000 )).ToString().HashMD5();
                users.SetActivationCode( user.Login, activationCode );

                Uri requestUrl = Url.RequestContext.HttpContext.Request.Url;
                string activationLink = string.Format( "{0}://{1}{2}", requestUrl.Scheme, requestUrl.Authority,
                    Url.Action( "ResetPassword", "User", new { user = Url.Encode( user.Login ), token = activationCode } ) );

                try
                {
                    Helpers.SendEmail( user.Email, "PastExplorer password recovery",
                        string.Format( "Hello, click <a href=\"{0}\">here</a> to change your PastExplorer account password.", activationLink ) );
                }
                catch ( Exception )
                {
                    ViewBag.ErrorMessage = "Failed to send password recovery e-mail message. Please try again later.";
                    return View( restorePassword );
                }

                return RedirectToAction( "Index", "Home" );
            }

            return View( restorePassword );
        }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:35,代码来源:UserController.cs

示例5: Register

        public async Task<ActionResult> Register(Register model)
        {
            if (ModelState.IsValid)
            {
                var userRepository = new UserRepository();

                var user = userRepository.GetByEmail(model.Email);

                if (user != null ) {
                    RedirectToAction("Register");
                }

                var authService = new AuthServise();

                var userModel = new UserModel {
                    Email = model.Email,
                    Name = model.Email,
                    CreateDate = DateTime.Now
                };

                authService.RegisterUser(userModel, model.Password);

                RedirectToAction("Login");
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
开发者ID:SokolovAlex,项目名称:private_chat_net,代码行数:28,代码来源:AccountController.cs

示例6: Register

        public async Task<dynamic> Register([FromBody] JToken jsonbody)
        {
            //validate data
            if (jsonbody == null || jsonbody.Type != JTokenType.Object)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data."));

            var email = jsonbody.SelectToken("email");
            if (email == null || string.IsNullOrWhiteSpace(email.ToString()))
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "email is missed."));

            var password = jsonbody.SelectToken("password");
            if (password == null || string.IsNullOrWhiteSpace(password.ToString()))
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "password is missed."));

            var displayName = jsonbody.SelectToken("displayname");
            if (displayName == null || string.IsNullOrWhiteSpace(displayName.ToString()))
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "displayname is missed."));

            //check if user exists or not
            var userRepo = new UserRepository();
            var userEntity = await userRepo.GetByEmail(email.ToString());
            if (userEntity != null)
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User exists already."));

            //save to db
            userEntity = new UserEntity
                {
                    Password = Encryptor.GetInstance().Encrypt(password.ToString()),
                    DisplayName = displayName.ToString(),
                    Emails = new List<string> {email.ToString()}
                };

            var options = (JObject)jsonbody.SelectToken("options");
            if (options != null )
            {
                userEntity.Options = new Dictionary<string, string>();
                foreach (var jProperty in options.Properties())
                {
                    userEntity.Options.Add(jProperty.Name, jProperty.Value.ToString());
                }
            }

            userRepo.Add(userEntity);

            return Ok(new { id = userEntity.ID });
        }
开发者ID:pdlg-spotlight,项目名称:lambda-architecture,代码行数:46,代码来源:AccountController.cs

示例7: IsValid

 public override bool IsValid(object value)
 {
     UserRepository userRepository = new UserRepository();
     return userRepository.GetByEmail( value as string ) == null;
 }
开发者ID:qbajas,项目名称:PhotoHistory,代码行数:5,代码来源:ValidationAttributes.cs

示例8: ProcessNewUserRecord

        private HttpResponseMessage ProcessNewUserRecord(HttpRequestMessage request, UserDTO uDto, string key, int companyId, int userId)
        {
            var ur = new UserRepository();

            //var userRepository = new AppUserRepository();
            var user = new User();
            bool newfromsetup;
            if (uDto.CompanyId == null)
            {
                uDto.CompanyId = companyId.ToString();
                newfromsetup = false;
            }
            else
            {
                newfromsetup = true;
            }
            //int? companyIdx = -1;
            if (ur.GetByEmail(uDto.EmailAddress) != null)
            {

                var msg = "Unable to add new user.  Email Address already Exists.";
                return Request.CreateResponse(HttpStatusCode.BadRequest, msg);
            }
            var validationErrors = GetValidationErrors(ur, user, uDto, companyId, userId);

            if (validationErrors.Any())
            {
                return ProcessValidationErrors(request, validationErrors, key);
            }
            //  no validation errors...
            //if (uDto.Password != "sg")
            //{
            //    user.Password = SecurityUtils.GetBinaryPassword(uDto.Password.ToString());
            //}
            //else
            //{
            //    SGApp.Models.EF.User userexist = userRepository.GetUser(uDto.EmailAddress, SecurityUtils.GetBinaryPassword(uDto.Password), ref companyIdx);
            //    user.Password = userexist.Password;
            //}
            //user.CompanyId = companyId;
            //user.UserId = null;
            user = ur.Save(user);
            if (newfromsetup)
            {
                var rr = new RoleRepository();
                var roles = rr.GetRoles();
                foreach (Role role in roles)
                {
                    var aur = new AppUserRoleRepository();
                    var urole = new UserRole();
                    //ur = aur.GetByUserAndRoleIds(contactId, int.Parse(cqDto.RoleID));
                    urole.UserId = user.UserId;
                    urole.RoleId = role.RoleId;
                    aur.Save(urole);
                }
            }
            uDto.Key = key;
            uDto.UserId = user.UserId.ToString();
            var response = request.CreateResponse(HttpStatusCode.Created, uDto);
            response.Headers.Location = new Uri(Url.Link("Default", new
            {
                id = user.UserId
            }));
            return response;
        }
开发者ID:Stimulant-Software,项目名称:HarvestSelect,代码行数:65,代码来源:UserController.cs


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