示例#1
0
        public void Create(CreateUserMessage message)
        {
            string query = "INSERT INTO dbo.users (id,username, password, role) " +
                           "VALUES (@Id,@Username,@Password,@Role) ";

            using (var connection = _connection.InitSqlConnection())
            {
                using (var command = new SqlCommand(query, connection))
                {
                    command.Parameters.Add("@Id", SqlDbType.UniqueIdentifier).Value     = Guid.NewGuid();
                    command.Parameters.Add("@Username", SqlDbType.NVarChar, 50).Value   = message.Username;
                    command.Parameters.Add("@Password", SqlDbType.NVarChar, 4000).Value = message.Password;
                    command.Parameters.Add("@Role", SqlDbType.NVarChar, 50).Value       = message.Role.ToString();

                    try
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex);
                        throw;
                    }
                }
            }
        }
示例#2
0
        public async Task <bool> CreateUserQueue([FromBody] CreateUserMessage createUser)
        {
            var queue = await _bus.Advanced.QueueDeclareAsync("platform.queue.createuser", true, false, true);

            //_bus.Advanced.PublishAsync()
            //await _bus.PubSub.PublishAsync(createUser, topic: Consts.Topic.User);
            return(true);
        }
示例#3
0
        public ActionResult CreateUser(CreateUserMessage message)
        {
            var baseUrl       = System.Configuration.ConfigurationManager.AppSettings["SingleSignOnUsersServicePath"];
            var uri           = baseUrl;
            var httpClient    = new HttpClient();
            var stringContent = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8, "application/json");
            var response      = httpClient.PostAsync(uri, stringContent).Result;
            var resp          = JsonConvert.DeserializeObject <CreateUserResultMessage>(response.Content.ReadAsStringAsync().Result);

            if (resp.Success)
            {
                return(RedirectToAction("Index", "Admin", new { showSuccessCreateUser = true }));
            }
            ModelState.AddModelError("Error", string.Join("<br/>", resp.ValidationResult.Errors.Select(x => x.ErrorMessage)));
            return(View("~/Views/Admin/Index.cshtml"));
        }
        private static CreateUserMessage CreateUserMessage()
        {
            const string password      = "******";
            var          testCode      = Guid.NewGuid().ToString("N").Substring(0, 8);
            var          testEmail     = new Faker().Internet.Email();
            var          testName      = new Faker().Name.FullName();
            var          createMessage = new CreateUserMessage
            {
                Code     = testCode,
                Email    = testEmail,
                Name     = testName,
                Password = password
            };

            return(createMessage);
        }
示例#5
0
        public void DataMustBeSavedToDatabaseOnceSuccessfulPassValidation()
        {
            var fakeUserRepo  = A.Fake <IUserRepository>();
            var fakeValidator = new CreateUserValidator(fakeUserRepo);

            var testMessage = new CreateUserMessage
            {
                Username = "******",
                Password = "******",
                Role     = UserRole.Admin
            };
            var handler = new CreateUserHandler(fakeUserRepo, fakeValidator);

            handler.Handle(testMessage);

            A.CallTo(() => fakeUserRepo.Create(testMessage)).MustHaveHappened();
        }
示例#6
0
        protected void CreateUserButton_Click(object sender, EventArgs e)
        {
            if (Password.Text != ConfirmPassword.Text)
            {
                ErrorMessage.Text = "Error";

                CustomValidator err = new CustomValidator();
                err.ValidationGroup = "RegisterUserValidationGroup";
                err.IsValid         = false;
                err.ErrorMessage    = "Passwords do not match";
                Page.Validators.Add(err);
                return;
            }

            CreateUserMessage CreateUserMsg = new CreateUserMessage();

            CreateUserMsg.FirstName = this.FirstName.Text;
            CreateUserMsg.LastName  = this.LastName.Text;
            CreateUserMsg.Password  = Password.Text;
            CreateUserMsg.Email     = Email.Text;

            i9Message responseMsg = i9MessageManagerBLL.SendMessage(MobileMessageType.Admin, AdminType.CreateUser, "Register", CreateUserMsg.GetType(), CreateUserMsg);

            if (responseMsg.ErrorStatus.IsError)
            {
                ErrorMessage.Text = "Error";

                CustomValidator err = new CustomValidator();
                err.ValidationGroup = "RegisterUserValidationGroup";
                err.IsValid         = false;
                err.ErrorMessage    = responseMsg.ErrorStatus.ErrorMsg;
                Page.Validators.Add(err);

                //RegisterUserValidationSummary.
                return;
            }



            //if (responseMsg.MsgBodyDataSet.Tables[0].Rows.Count <= 0)
            //{
            //    ErrorMessage.Text = "Unable to create new user, please try again.";
            //    return;
            //}
            Response.Redirect(@"~\Account\Login.aspx?Login=Success");
        }
        public override async Task <User> Create(CreateUserMessage message, ServerCallContext context)
        {
            int resultId;
            var userDto = _mapper.Map <UserDto>(message);

            try
            {
                resultId = await _coreService.Create(userDto);
            }
            catch (Exception)
            {
                return(null);
            }

            var result = _mapper.Map <User>(message);

            result.Id = resultId;

            return(result);
        }
示例#8
0
        public async Task <bool> CreateUserAck([FromBody] CreateUserMessage message)
        {
            await _bus.PubSub.PublishAsync(message, topic : Consts.Topic.User)
            .ContinueWith(task =>
            {
                if (task.IsCompleted && !task.IsCompletedSuccessfully)
                {
                    Logger.LogInformation($"消息 {message.UserName} 推送 broken 失败");
                }
                if (task.IsCompletedSuccessfully)
                {
                    Logger.LogInformation($"消息 {message.UserName} 推送确认");
                }
                if (task.IsFaulted)
                {
                    Logger.LogError($"系统错误:{task.Exception.Message}");
                }
            });

            return(true);
        }
示例#9
0
        public override async Task <BaseResponse> Create(CreateUserMessage message, ServerCallContext context)
        {
            var result = new BaseResponse();

            try
            {
                await _coreService.Create(new UserDto
                {
                    Code     = message.Code,
                    Name     = message.Name,
                    Email    = message.Email,
                    Password = EncodePassword(message.Password)
                });

                result.Code = ResponseCode.Success;
            }
            catch (Exception)
            {
                result.Code = ResponseCode.GeneralError;
            }
            return(result);
        }
示例#10
0
        public async Task Test_Create_User()
        {
            // Arrange
            const string code          = "testNew001";
            const string email         = "*****@*****.**";
            const string name          = "TestNew001";
            const string password      = "******";
            var          createMessage = new CreateUserMessage
            {
                Code     = code,
                Email    = email,
                Name     = name,
                Password = password
            };
            var expectedUserCount = default(int);

            // Action
            var actualResponseCode = default(ResponseCode);
            var actualUser         = default(User);
            var actualUserCount    = default(int);

            await RollBackTransactionScope(async (connection, transaction) =>
            {
                var serviceImpl    = GetServiceImpl(connection, transaction);
                expectedUserCount  = (await serviceImpl.GetAll(new Empty(), null)).Value.Count + 1;
                actualResponseCode = (await serviceImpl.Create(createMessage, null)).Code;
                var allUsers       = (await serviceImpl.GetAll(new Empty(), null)).Value;
                actualUser         = allUsers.First(user => user.Code == code);
                actualUserCount    = allUsers.Count;
            });

            // Assert
            Assert.AreEqual(ResponseCode.Success, actualResponseCode);
            Assert.AreEqual(code, actualUser.Code);
            Assert.AreEqual(name, actualUser.Name);
            Assert.AreEqual(email, actualUser.Email);
            Assert.AreEqual(expectedUserCount, actualUserCount);
        }
示例#11
0
        public async Task <bool> CreateUser([FromBody] CreateUserMessage createUser)
        {
            await _bus.PubSub.PublishAsync(createUser, topic : Consts.Topic.User);

            return(true);
        }
        public async Task <ResponseBaseModel <string> > CreateUser([FromBody] CreateUserMessage request)
        {
            await _serviceClient.CreateAsync(request);

            return(new ResponseBaseModel <string>(ResponseCode.Success, null));
        }
示例#13
0
        public HttpResponseMessage Post(CreateUserMessage message)
        {
            var output = _mediator.Send(message);

            return(Request.CreateResponse(output.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest, output));
        }
示例#14
0
        public async Task <ResponseBaseModel <string> > CreateUser([FromBody] CreateUserMessage request)
        {
            var result = await _serviceClient.CreateAsync(request);

            return(new ResponseBaseModel <string>((ResponseCode)result.Code, null));
        }
示例#15
0
        public void launchApp()
        {
            Console.WriteLine("Connecting to the chat app");

            // read expression
            Message testUser = Net.receiveMessage(comm.GetStream());

            if (testUser.GetType().Name.Equals("MessageUser"))
            {
                //Used to check if the user is valid
                bool valid = false;

                // read expression
                MessageUser testUserConnect = (MessageUser)testUser;

                Console.WriteLine("Login and password received");
                // send result

                foreach (User u in users)
                {
                    if (testUserConnect.Login.Equals(u.Login) && testUserConnect.Password.Equals(u.Password))
                    {
                        valid = true;
                    }
                }

                if (valid)
                {
                    //Send the user with a boolean to display the result (if success or not)
                    Net.sendMessage(comm.GetStream(), new MessageUser(testUserConnect.Login, testUserConnect.Password, false));

                    //Make the connection by putting the user in the object connectionUser
                    User connectionUser = null;
                    foreach (User u in users)
                    {
                        if (u.Login.Equals(testUserConnect.Login) && u.Password.Equals(testUserConnect.Password))
                        {
                            connectionUser = u;
                        }
                    }

                    //Add the user to the list of connected people and send back the user to the client
                    connectedUsers.Add(connectionUser);
                    Net.sendMessage(comm.GetStream(), new MessageUser(connectionUser.Id_user, connectionUser.Login, connectionUser.Password, true));
                    Console.WriteLine("You are connected as " + connectionUser.Login);


                    //Test to store users with their tcpclient
                    bool found = false;
                    foreach (KeyValuePair <User, List <TcpClient> > myClients in userTcps)
                    {
                        if (myClients.Key.Equals(connectionUser))
                        {
                            myClients.Value.Add(comm);
                            found = true;
                        }
                    }
                    if (found == false)
                    {
                        List <TcpClient> newClient = new List <TcpClient>();
                        newClient.Add(comm);
                        userTcps.Add(connectionUser, newClient);
                    }
                    Console.WriteLine("Added " + connectionUser.Login + " with the comm : " + comm.Client.RemoteEndPoint);


                    Console.WriteLine("Here are the connected users");
                    foreach (User u in connectedUsers)
                    {
                        Console.WriteLine("<" + u.Login + ">");
                    }


                    Thread connectedActionThread = new Thread(new ParameterizedThreadStart(connectedActions));
                    connectedActionThread.Start(true);
                }
                else
                {
                    //Same as before
                    Net.sendMessage(comm.GetStream(), new MessageUser(testUserConnect.Login, testUserConnect.Password, true));
                    launchApp();
                }
            }
            else if (testUser.GetType().Name.Equals("CreateUserMessage"))
            {
                //Receive the datas from the client side
                CreateUserMessage user = (CreateUserMessage)testUser;


                //Add the client to the tab
                users.Add(new User(users.Count + 1, user.Login, user.Password));

                //Print the users created
                Console.WriteLine("Table users updated : ");

                foreach (User u in users)
                {
                    Console.WriteLine(u.Login + " " + u.Password);
                }
                Console.WriteLine("\n");

                //Relaunche the menu when finish creation
                launchApp();
            }
        }
示例#16
0
        private i9Message CreateUser(i9Message requestMessage)
        {
            i9Message response = new i9Message();

            string            CodeSetName        = requestMessage.MsgBody;
            CreateUserMessage oCreateUserMessage = (CreateUserMessage)i9Message.XMLDeserializeMessage(typeof(CreateUserMessage), requestMessage.MsgBody);

            SQLAccess da  = new SQLAccess();
            string    SQL = " Select * FROM i9SysPersonnel WHERE Email = " + SQLUtility.SQLString(oCreateUserMessage.Email) + " ";

            Dictionary <string, string> tableMapping = new Dictionary <string, string>()
            {
                { "Table", "i9SysPersonnel" }
            };

            DataSet ds = da.GetDataSet(SQL, tableMapping);

            if (ds.Tables["i9SysPersonnel"].Rows.Count > 0)
            {
                response.ErrorStatus.ErrorMsg = "Email already exists in system";
                response.ErrorStatus.IsError  = true;
                return(response);
            }
            else
            {
                DataRow dr = ds.Tables["i9SysPersonnel"].NewRow();

                dr["FirstName"] = oCreateUserMessage.FirstName;
                dr["LastName"]  = oCreateUserMessage.LastName;

                dr["DateTimeInserted"] = DateTime.Now;
                dr["DateTimeUpdated"]  = DateTime.Now;

                dr["Password"]         = oCreateUserMessage.Password;
                dr["Email"]            = oCreateUserMessage.Email;
                dr["BadgeNumber"]      = oCreateUserMessage.Email;
                dr["i9SysPersonnelID"] = Guid.NewGuid();
                dr["ActivationGuid"]   = Guid.NewGuid();
                dr["Enabled"]          = 1;
                dr["DemoUser"]         = 1;
                dr["OfficerORI"]       = "";
                dr["Officer"]          = oCreateUserMessage.FirstName + ", " + oCreateUserMessage.LastName;

                if (oCreateUserMessage.i9AgencyID == Guid.Empty)
                {
                    dr["i9AgencyID"] = "53A05F38-FC9C-4260-B939-CB1F3998C4D4";
                }
                else
                {
                    dr["i9AgencyID"] = oCreateUserMessage.i9AgencyID;
                }

                ds.Tables["i9SysPersonnel"].Rows.Add(dr);

                da.SaveDataTable(ds.Tables["i9SysPersonnel"]);

                //===============================================================
                //  Send Email Confirmation
                //===============================================================
                //string EmailMessage = "";
                //string EmailSubject = "Invert911 Activation Confirmation";
                //string EmailFrom = "*****@*****.**";
                //string EmailTo = oCreateUserMessage.Email;

                //EmailUtility.SendEmail(EmailTo,EmailFrom,EmailSubject, EmailMessage);
            }

            response.ErrorStatus.IsError = false;
            return(response);
        }