示例#1
0
 public async Task <UserEntity> Get(string[] key, string[] value)
 {
     return(await Task <UserEntity> .Run(() => {
         UserTableEntity userTableEntity = this.cloudTable.Get(key, value).Result;
         return this.toEntity(userTableEntity);
     }));
 }
 public static User ToUser(this UserTableEntity userEntity)
 {
     return(new User(
                userEntity.RowKey,
                userEntity.UserName,
                userEntity.IsActive
                ));
 }
示例#3
0
 public static User toUser(this UserTableEntity user)
 {
     return(new User()
     {
         Nombre = user.Nombre,
         Rol = user.Rol,
         PartitionKey = user.PartitionKey,
         RowKey = user.RowKey
     });
 }
示例#4
0
 public static User ToUser(this UserTableEntity user)
 {
     return(new User()
     {
         Id = user.RowKey,
         CreatedTime = user.CreatedTime,
         IsActive = user.IsActive,
         Name = user.Name
     });
 }
示例#5
0
        public void InsertNewUser(string clientId)
        {
            _logger.LogDebug("Inserting new UserTableEntity - " + clientId);
            CloudTable      userTable       = GetUserTable();
            UserTableEntity newUser         = new UserTableEntity(clientId);
            TableOperation  insertNewUserOp = TableOperation.Insert(newUser);

            userTable.ExecuteAsync(insertNewUserOp);
            _logger.LogDebug("Finished inserting new UserTableEntity - " + clientId);
        }
示例#6
0
        public void UserTableEntity_IdIsPartitionKey()
        {
            var user = new User
            {
                Id     = "id",
                Handle = "handle"
            };

            var tableEntity = new UserTableEntity(user);

            Assert.Equal(user.Id, tableEntity.PartitionKey);
        }
示例#7
0
 public static IActionResult GetUserById(
     [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = Route + "/{id}")] HttpRequest req,
     [Table(TableName, "signup", "{id}", Connection = "AzureWebJobsStorage")] UserTableEntity userTableEntity,
     ILogger log, string id)
 {
     log.LogInformation("Getting user by id");
     if (userTableEntity == null)
     {
         log.LogInformation($"User {id} not found");
         return(new NotFoundResult());
     }
     return(new OkObjectResult(userTableEntity.ToUser()));
 }
示例#8
0
        public void UserTableEntity_ValuesSetFromUserCorrectly()
        {
            var user = new User
            {
                Id     = "id",
                Handle = "handle"
            };

            var tableEntity = new UserTableEntity(user);

            Assert.Equal(user.Id, tableEntity.Id);
            Assert.Equal(user.Handle, tableEntity.Handle);
        }
        public async Task AzureStorageActiveUserRepository_RemoveUserReturnsHandle()
        {
            var entity = new UserTableEntity()
            {
                Id     = "id",
                Handle = "handle"
            };

            _clientMock.Setup(c => c.RemoveEntity <UserTableEntity>("id", String.Empty)).Returns(Task.FromResult(entity));

            var result = await _repository.RemoveUser("id");

            Assert.Equal(entity.Handle, result);
        }
示例#10
0
        public void UpdateUserScore(string sClanName, string sUserName, string sGameType, int iScore)
        {
            // get the requested user row from the table
            TableOperation pUserRetrieveOp     = TableOperation.Retrieve <UserTableEntity>(Master.BuildUserPartitionKey(sClanName), sUserName);
            TableResult    pUserRetrieveResult = this.Table.Execute(pUserRetrieveOp);

            if (pUserRetrieveResult.Result == null)
            {
                return;
            }
            UserTableEntity pUser = (UserTableEntity)pUserRetrieveResult.Result;

            if (sGameType == "Zendo")
            {
                pUser.ZendoScore += iScore;
            }
            this.Table.Execute(TableOperation.Replace(pUser));
        }
示例#11
0
        public UserTableEntity toTableEntity(UserEntity entity)
        {
            if (string.IsNullOrWhiteSpace(entity.WorkSpaceID))
            {
                entity.WorkSpaceID = "default";
            }
            UserTableEntity tableentity = new UserTableEntity(entity.WorkSpaceID, entity.UserID);

            if (!string.IsNullOrWhiteSpace(entity.JobTitle))
            {
                tableentity.JobTitle = entity.JobTitle;
            }

            if (!string.IsNullOrWhiteSpace(entity.Language))
            {
                tableentity.Language = entity.Language;
            }

            if (!string.IsNullOrWhiteSpace(entity.LastName))
            {
                tableentity.LastName = entity.LastName;
            }

            if (!string.IsNullOrWhiteSpace(entity.Role))
            {
                tableentity.Role = entity.Role;
            }

            if (!string.IsNullOrWhiteSpace(entity.DisplayName))
            {
                tableentity.DisplayName = entity.DisplayName;
            }

            if (!string.IsNullOrWhiteSpace(entity.Email))
            {
                tableentity.Email = entity.Email;
            }



            return(tableentity);
        }
示例#12
0
        public UserEntity toEntity(UserTableEntity tableentity)
        {
            UserEntity entity = new UserEntity();

            entity.WorkSpaceID = tableentity.RowKey;
            entity.UserID      = tableentity.PartitionKey;

            if (!string.IsNullOrWhiteSpace(tableentity.Language))
            {
                entity.Language = tableentity.Language;
            }

            if (!string.IsNullOrWhiteSpace(tableentity.LastName))
            {
                entity.LastName = tableentity.LastName;
            }

            if (!string.IsNullOrWhiteSpace(tableentity.JobTitle))
            {
                entity.JobTitle = tableentity.JobTitle;
            }

            if (!string.IsNullOrWhiteSpace(tableentity.Role))
            {
                entity.Role = tableentity.Role;
            }

            if (!string.IsNullOrWhiteSpace(tableentity.Email))
            {
                entity.Email = tableentity.Email;
            }

            if (!string.IsNullOrWhiteSpace(tableentity.DisplayName))
            {
                entity.DisplayName = tableentity.DisplayName;
            }

            return(entity);
        }
示例#13
0
        public string JoinClan(string sEmail, string sClanName, string sClanPassPhrase, string sUserName, string sUserPassPhrase)
        {
            // make sure the clan password is correct
            if (!VerifyClanPassPhrase(sClanName, sClanPassPhrase))
            {
                return(Master.MessagifyError("Clan password incorrect."));
            }

            // make sure the username doesn't already exist
            TableOperation pUserRetrieveOp = TableOperation.Retrieve <UserTableEntity>(Master.BuildUserPartitionKey(sClanName), sUserName);

            if (this.Table.Execute(pUserRetrieveOp).Result != null)
            {
                // if just user logging in on a different device
                if (VerifyUserPassPhrase(sClanName, sUserName, sUserPassPhrase))
                {
                    return(Master.Messagify("You have successfully logged into " + sClanName + " as " + sUserName, Master.MSGTYPE_BOTH, "<ClanStub ClanName='" + sClanName + "' UserName='******' />"));
                }

                // (password incorrect)
                return(Master.MessagifyError("User with this name already exists in this clan."));
            }

            // if we make it to this point, we're good, add a new user!
            UserTableEntity pUser = new UserTableEntity(sClanName, sUserName);

            pUser.PassPhrase = this.Sha256Hash(sUserPassPhrase);
            pUser.Email      = sEmail;
            this.Table.Execute(TableOperation.Insert(pUser));

            // add the email/clan/username association
            RegistrationClanUserTableEntity pUserClan = new RegistrationClanUserTableEntity(sEmail, sClanName, sUserName);

            this.Table.Execute(TableOperation.Insert(pUserClan));

            //return "You have successfully joined the clan " + sClanName + " as " + sUserName;
            return(Master.Messagify("You have successfully joined the clan " + sClanName + " as " + sUserName, Master.MSGTYPE_BOTH, "<ClanStub ClanName='" + sClanName + "' UserName='******' />"));
        }
示例#14
0
        public bool VerifyUserPassPhrase(string sClanName, string sUserName, string sUserPassPhrase)
        {
            if (sClanName == null || sUserName == null || sUserPassPhrase == null || sUserPassPhrase == "")
            {
                return(false);
            }

            // get the requested user row from the table
            TableOperation pUserRetrieveOp     = TableOperation.Retrieve <UserTableEntity>(Master.BuildUserPartitionKey(sClanName), sUserName);
            TableResult    pUserRetrieveResult = this.Table.Execute(pUserRetrieveOp);

            if (pUserRetrieveResult.Result == null)
            {
                return(false);
            }
            UserTableEntity pUser = (UserTableEntity)pUserRetrieveResult.Result;

            // hash user passphrase
            string sUserHash = Security.Sha256Hash(sUserPassPhrase);

            // check if the passphrase matches
            return(sUserHash == pUser.PassPhrase);
        }
        public async Task <ActionResult> SignUp()
        {
            string input = null;

            // If not data came in, then return
            if (this.Request.Body == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is null", HttpStatusCode.Conflict)));
            }

            // Read the input claims from the request body
            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                input = await reader.ReadToEndAsync();
            }

            // Check input content value
            if (string.IsNullOrEmpty(input))
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is empty", HttpStatusCode.Conflict)));
            }

            // Convert the input string into InputClaimsModel object
            InputClaimsModel inputClaims = InputClaimsModel.Parse(input);

            if (inputClaims == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Can not deserialize input claims", HttpStatusCode.Conflict)));
            }

            if (string.IsNullOrEmpty(inputClaims.objectId))
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("User object Id is null or empty", HttpStatusCode.Conflict)));
            }

            try
            {
                CloudTable table = await this.GetUsersTable(this.AppSettings.BlobStorageConnectionString);

                // Create a new user entity.
                UserTableEntity user = new UserTableEntity(inputClaims.objectId,
                                                           inputClaims.email,
                                                           inputClaims.displayName,
                                                           inputClaims.givenName,
                                                           inputClaims.surName);

                // Create the TableOperation object that inserts the customer entity.
                TableOperation insertOperation = TableOperation.InsertOrReplace(user);

                // Execute the insert operation.
                await table.ExecuteAsync(insertOperation);

                return(StatusCode((int)HttpStatusCode.OK, new B2CResponseModel(string.Empty, HttpStatusCode.OK)
                {
                    //emailHash = this.HashSHA1(inputClaims.email)
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel($"General error (REST API): {ex.Message}", HttpStatusCode.Conflict)));
            }
        }
        public async Task <ActionResult> SignIn()
        {
            string input = null;

            // If not data came in, then return
            if (this.Request.Body == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is null", HttpStatusCode.Conflict)));
            }

            // Read the input claims from the request body
            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                input = await reader.ReadToEndAsync();
            }

            // Check input content value
            if (string.IsNullOrEmpty(input))
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is empty", HttpStatusCode.Conflict)));
            }

            // Convert the input string into InputClaimsModel object
            InputClaimsModel inputClaims = InputClaimsModel.Parse(input);

            if (inputClaims == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Can not deserialize input claims", HttpStatusCode.Conflict)));
            }

            if (string.IsNullOrEmpty(inputClaims.objectId))
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("User object Id is null or empty", HttpStatusCode.Conflict)));
            }

            try
            {
                CloudTable table = await this.GetUsersTable(this.AppSettings.BlobStorageConnectionString);

                // Create a retrieve operation that takes a customer entity.
                TableOperation retrieveOperation = TableOperation.Retrieve <UserTableEntity>(Consts.MigrationTablePartition, inputClaims.objectId.ToLower());

                // Execute the retrieve operation.
                TableResult retrievedResult = await table.ExecuteAsync(retrieveOperation);

                // Print the phone number of the result.
                if (retrievedResult.Result != null)
                {
                    UserTableEntity user = (UserTableEntity)retrievedResult.Result;
                    return(StatusCode((int)HttpStatusCode.OK, new B2CResponseModel(string.Empty, HttpStatusCode.OK)
                    {
                        email = user.Email,
                        displayName = user.DisplayName,
                        givenName = user.GivenName,
                        surName = user.SurName
                    }));
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("User profile not found", HttpStatusCode.Conflict)));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel($"General error (REST API): {ex.Message}", HttpStatusCode.Conflict)));
            }
        }
示例#17
0
        public async Task <bool> Update(UserEntity entity)
        {
            UserTableEntity userTableEntity = this.toTableEntity(entity);

            return(await this.cloudTable.Update(userTableEntity));
        }
        public async Task <ActionResult> Migrate()
        {
            string input = null;

            // If not data came in, then return
            if (this.Request.Body == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is null", HttpStatusCode.Conflict)));
            }

            // Read the input claims from the request body
            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                input = await reader.ReadToEndAsync();
            }

            // Check input content value
            if (string.IsNullOrEmpty(input))
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is empty", HttpStatusCode.Conflict)));
            }

            // Convert the input string into InputClaimsModel object
            InputClaimsModel inputClaims = InputClaimsModel.Parse(input);

            if (inputClaims == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Can not deserialize input claims", HttpStatusCode.Conflict)));
            }

            if (string.IsNullOrEmpty(inputClaims.signInName))
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("User 'signInName' is null or empty", HttpStatusCode.Conflict)));
            }

            //if (string.IsNullOrEmpty(inputClaims.password))
            //{
            //    return StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Password is null or empty", HttpStatusCode.Conflict));
            //}

            // Initiate the output claim object
            B2CResponseModel outputClaims = new B2CResponseModel("", HttpStatusCode.OK);

            // Create a retrieve operation that takes a customer entity.
            // Note: Azure Blob Table query is case sensitive, always set the input email to lower case
            var retrieveOperation = TableOperation.Retrieve <UserTableEntity>(Consts.MigrationTablePartition, inputClaims.signInName.ToLower());

            CloudTable table = await GetSignUpTable(this.AppSettings.BlobStorageConnectionString);

            // Execute the retrieve operation.
            TableResult tableEntity = await table.ExecuteAsync(retrieveOperation);


            if (tableEntity != null && tableEntity.Result != null)
            {
                UserTableEntity userMigrationEntity = ((UserTableEntity)tableEntity.Result);
                try
                {
                    outputClaims.needToMigrate = "local";

                    // Compare the password entered by the user and the one in the migration table.
                    // Don't compare in password reset flow (useInputPassword is true)
                    if (inputClaims.useInputPassword || (inputClaims.password == userMigrationEntity.Password))
                    {
                        outputClaims.newPassword = inputClaims.password;
                        outputClaims.email       = inputClaims.signInName;
                        outputClaims.displayName = userMigrationEntity.DisplayName;
                        outputClaims.surName     = userMigrationEntity.LastName;
                        outputClaims.givenName   = userMigrationEntity.FirstName;

                        // Remove the user entity from migration table
                        TableOperation deleteOperation = TableOperation.Delete((UserTableEntity)tableEntity.Result);
                        await table.ExecuteAsync(deleteOperation);
                    }
                    else
                    {
                        return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Your password is incorrect (migration API)", HttpStatusCode.Conflict)));
                    }
                }
                catch (Exception ex)
                {
                    return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel($"User migration error: {ex.Message}", HttpStatusCode.Conflict)));
                }
            }

            return(Ok(outputClaims));
        }