예제 #1
0
        public bool Insert(string userName, string password)
        {
            var userEntity = new BlogUserEntity()
            {
                Nickname = userName,
                UserName = userName,
                Password = password,
            };
            var v = _repository.FirstOrDefault(x => x.UserName == userName);

            if (v == null)
            {
                _repository.Insert(userEntity);
                return(true);
            }
            return(false);
        }
예제 #2
0
        public AuthResult Register(RegisterModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (String.IsNullOrWhiteSpace(model.Name) || String.IsNullOrWhiteSpace(model.Nick) ||
                string.IsNullOrWhiteSpace(model.Password))
            {
                return new AuthResult {
                           Message = "Incorrect fields!"
                }
            }
            ;

            var user = new BlogUser {
                Nick = model.Nick, UserPassword = model.Password, Name = model.Name
            };
            var userId = _blogUserRepository.Insert(user);

            if (userId > 0)
            {
                var token = _accessTokenGenerator.GenerateToken(userId, model.Nick);

                var blogUser = _blogUserRepository.GetById(userId);

                return(new AuthResult {
                    Token = token, Message = "Ok", User = blogUser
                });
            }

            return(new AuthResult {
                Message = "Can't save user!"
            });
        }
    }
예제 #3
0
        public BlogUser Register(BlogUser user)
        {
            var id = _blogUserRepository.Insert(user);

            return(_blogUserRepository.GetById(id));
        }