Exemplo n.º 1
0
        public SingleResult <UserDTO> GetUser(string id)
        {
            var claimsPrincipal = User as ClaimsPrincipal;
            var userId          = BaseAuth.GetUserId(claimsPrincipal);

            return(Lookup(userId));
        }
Exemplo n.º 2
0
 public HttpResponseMessage GetCurrentUser()
 {
     try
     {
         var user    = BaseAuth.GetUser(_context, RequestContext);
         var mapper  = _config.CreateMapper();
         var userDto = mapper.Map <Models.User, UserDTO>(user);
         return(Request.CreateResponse(HttpStatusCode.OK, new Response <UserDTO>(ApiResult.Ok, userDto)));
     }
     catch (ApiException ex)
     {
         return(Request.CreateResponse(HttpStatusCode.OK,
                                       new Response <UserDTO>(ex.ApiResult, null, new ErrorResponse(ex.ErrorType, ex.Message, ex))));
     }
     catch (EntitySqlException ex)
     {
         return(Request.CreateResponse(HttpStatusCode.OK,
                                       new Response <UserDTO>(ApiResult.Sql, null, new ErrorResponse(ErrorType.None, ex.Message, ex))));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.OK,
                                       new Response <UserDTO>(ApiResult.Unknown, null, new ErrorResponse(ErrorType.Internal, ex.Message, ex))));
     }
 }
Exemplo n.º 3
0
        public void CreateToken_ShouldReturnAuthToken()
        {
            var token = BaseAuth.CreateToken("standart:u1");

            Debug.WriteLine("# Token : ");
            Debug.WriteLine(token);
        }
Exemplo n.º 4
0
        public Task <UserDTO> PatchUser(Delta <UserDTO> patch)
        {
            var claimsPrincipal = User as ClaimsPrincipal;
            var userId          = BaseAuth.GetUserId(claimsPrincipal);

            return(UpdateAsync(userId, patch));
        }
Exemplo n.º 5
0
 public BanUser(BaseAuth auth)
 {
     InitializeComponent();
     AuthModel = auth;
     Users     = AuthModel.readAllUsers();
     Users.ForEach(user => checkedListBox1.Items.Add(user.Login, user.IsBanned));
 }
Exemplo n.º 6
0
        public HttpResponseMessage Post(PostDTO post)
        {
            try
            {
                var  claimsPrincipal = User as ClaimsPrincipal;
                var  user            = BaseAuth.GetUser(_context, claimsPrincipal);
                var  id     = SequentialGuid.NewGuid();
                Post dbPost = new Post
                {
                    UserId      = user.Id,
                    Description = post.Description,
                    Status      = PhotoStatus.Planned,
                    Type        = CheckData.GetPhotoType(user.Type),
                    Id          = id,
                    PhotoUrl    = Const.StorageBaseUrl + Const.StoragePostsContainer + "/" + id + ".jpeg"
                };

                var response = new Response <PostResponse>(ApiResult.Ok, new PostResponse {
                    Id = id
                });
                using (var storage = new AzureStorage())
                {
                    response.Data.Sas = storage.GetPostsSas();
                }


                _context.Posts.Add(dbPost);
                _context.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.Created, response));
            }
            catch (ApiException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <PostResponse>(ex.ApiResult, null, new ErrorResponse(ex.ErrorType, ex.Message, ex))));
            }
            catch (EntitySqlException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <PostResponse>(ApiResult.Sql, null, new ErrorResponse(ErrorType.None, ex.Message, ex))));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <PostResponse>(ApiResult.Unknown, null,
                                                                          new ErrorResponse(ErrorType.Internal, ex.Message, ex))));
            }
        }
Exemplo n.º 7
0
        public HttpResponseMessage Login(StandartAuthRequest request)
        {
            try
            {
                // Check request and request props is not null
                CheckVal.IsNull(request, nameof(request));
                CheckVal.IsNull(request.Password, nameof(request.Password));
                // Find User
                var user = CheckData.UserExist(_context, false, email: request.Email, name: request.Name);
                if (user == null)
                {
                    throw new ApiException(ApiResult.Validation, ErrorType.UserWithEmailorNameNotFound,
                                           request.Email ?? request.Name);
                }
                // Check if User is Blocked
                CheckData.IsUserBlocked(_context, null, user);
                // Check if User Account Exist
                var account = CheckData.AccountExist(_context, Provider.Standart, user.Id);
                // Check password
                BaseAuth.CheckPassword(user, request.Password);


                var token = BaseAuth.CreateToken(user.Id);

                var userDto = _mapper.Map <User, UserDTO>(user);

                // Generate AuthenticationToken
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <LoginResult>(ApiResult.Ok, new LoginResult(token, userDto))));
            }
            catch (ApiException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <LoginResult>(ex.ApiResult, null, new ErrorResponse(ex.ErrorType, ex.Message, ex))));
            }
            catch (EntitySqlException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <LoginResult>(ApiResult.Sql, null, new ErrorResponse(ErrorType.None, ex.Message, ex))));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <LoginResult>(ApiResult.Unknown, null,
                                                                         new ErrorResponse(ErrorType.Internal, ex.Message, ex))));
            }
        }
Exemplo n.º 8
0
        public Main(BaseAuth auth, UserEntry user)
        {
            InitializeComponent();
            AuthModel          = auth;
            Users              = AuthModel.readAllUsers();
            User               = user;
            nicknameLabel.Text = "User: "******"Admin")
            {
                usersPanel.Enabled = false;
            }
            else
            {
                DisplayUsers();
            }
        }
Exemplo n.º 9
0
        public void PostApiControllerTestInitialize()
        {
            _config = Mapping.Mapping.GetConfiguration();
            _mapper = _config.CreateMapper();
            TestDbPopulator.PopulateDb(2, 1);
            string token   = BaseAuth.CreateToken("u1");
            var    config  = new HttpConfiguration();
            var    request = new HttpRequestMessage {
                RequestUri = new Uri("http://localhost:50268/api/Post")
            };

            request.Headers.Add("x-zumo-auth", token);
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            _controller = new PostApiController(TestContext)
            {
                Request = request,
                User    = TestHelper.GetUser("u1")
            };
        }
Exemplo n.º 10
0
        public HttpResponseMessage Registration(StandartAuthRequest request)
        {
            try
            {
                // Check request and request props is not null
                CheckVal.IsNull(request, "request");
                CheckVal.IsNull(request.Email, nameof(request.Email));
                CheckVal.IsNull(request.Name, nameof(request.Name));
                CheckVal.IsNull(request.Password, nameof(request.Password));
                // We use lowercased User Names
                request.Email = request.Email.ToLower();
                request.Name  = request.Name.ToLower();
                // Validate request props
                CheckVal.EmailCheck(request.Email);

                CheckVal.NameCheck(request.Name);
                CheckVal.PasswordCheck(request.Password);
                // Check if User Already Exist
                CheckData.UserExist(_context, true, email: request.Email, name: request.Name);
                var newUser = BaseAuth.CreateUser(_context, Provider.Standart, request);
                return(Request.CreateResponse(HttpStatusCode.Created,
                                              new Response <string>(ApiResult.Created, newUser.Id)));
            }
            catch (ApiException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <string>(ex.ApiResult, null, new ErrorResponse(ex.ErrorType, ex.Message, ex))));
            }
            catch (EntitySqlException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <string>(ApiResult.Sql, null, new ErrorResponse(ErrorType.None, ex.Message, ex))));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new Response <string>(ApiResult.Unknown, null, new ErrorResponse(ErrorType.Internal, ex.Message, ex))));
            }
        }
Exemplo n.º 11
0
        public void UserController_ShouldReturnCurrentUser()
        {
            TestDbPopulator.PopulateUsers(2);
            TestDbPopulator.PopulateStandartAccounts(2);
            _user = TestDbPopulator.GetUser(1);
            var req = new StandartAuthRequest
            {
                Email    = _user.Email,
                Password = "******"
            };

            string token   = BaseAuth.CreateToken("u1");
            var    config  = new HttpConfiguration();
            var    request = new HttpRequestMessage {
                RequestUri = new Uri("http://localhost:50268/api/User")
            };

            request.Headers.Add("x-zumo-auth", token);
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            var username            = "******";
            var identity            = new GenericIdentity(username, "");
            var nameIdentifierClaim = new Claim(ClaimTypes.NameIdentifier, username);

            identity.AddClaim(nameIdentifierClaim);
            var principal = new GenericPrincipal(identity, new string[] {});
            var user      = new ClaimsPrincipal(principal);

            _controller = new UserApiController(TestContext)
            {
                Request = request,
                User    = user
            };
            var response = _controller.GetCurrentUser();
            var result   = TestHelper.ParseUserResponse(response);

            Assert.AreEqual("OK", result.StatusCode);
        }
Exemplo n.º 12
0
 public QueuePostDomainManager(TupapiContext context, HttpRequestMessage request, bool enableSoftDelete)
     : base(context, request, enableSoftDelete)
 {
     _userId = BaseAuth.GetUserId();
 }
 public ChangePassword(UserEntry user, BaseAuth auth)
 {
     InitializeComponent();
     User      = user;
     AuthModel = auth;
 }
Exemplo n.º 14
0
        public IQueryable <UserDTO> GetAllUsers()
        {
            var userId = BaseAuth.GetUserId(RequestContext);

            return(Query().Where(u => u.Id == userId));
        }
Exemplo n.º 15
0
 public bool AddSASLAuth(BaseAuth authMethod)
 {
     AuthMethod = authMethod;
     return(true);
 }
Exemplo n.º 16
0
 public AddUser(BaseAuth auth)
 {
     InitializeComponent();
     AuthModel = auth;
 }
Exemplo n.º 17
0
 public QueuePostDomainManager(TupapiContext context, HttpRequestMessage request)
     : base(context, request)
 {
     _userId = BaseAuth.GetUserId();
 }