Example #1
0
        public async Task CreateUserTest()
        {
            var user = await repo.AddUser("fred", "flintstone", "fred flintstone", "my pretty good password!01");

            var userId = user.Id;

            TestContext.Out.WriteLine($"User {userId} created.");
            Assert.IsNotNull(userId);
            await repo.DeleteUser(userId);

            TestContext.Out.WriteLine($"User {userId} deleted.");
        }
Example #2
0
 public async Task <ActionResult> SignUpAsync([Bind(Include = "Email, Pass")] User user)
 {
     if (ModelState.IsValid)
     {
         IUserRepo ur = new UserRepo();
         if (!ur.CheckUserByEmail(user.Email) && Constants.ZXCVBN(user.Pass) > 1)
         {
             ur.AddUser(new User(user.Email, user.Pass));
             IConfirmationCodeRepo cr = new ConfirmationCodeRepo();
             ConfirmationCode      cc;
             if (!cr.CheckConfirmationCodeByEmail(user.Email))
             {
                 cc = new ConfirmationCode(user.Email, false);
                 cr.AddConfirmationCode(cc);
                 await EmailSender.Activate(user.Email, cc.Code, "Activate your account");
             }
             else
             {
                 cc = cr.GetConfirmationCode(user.Email);
             }
             return(View("~/Views/User/ConfirmEmail.cshtml", cc));
         }
         else
         {
             return(View("~/Views/Home/SignUp.cshtml"));
         }
     }
     else
     {
         return(View("~/Views/Home/SignUp.cshtml"));
     }
 }
Example #3
0
        public static void Display(ViewModelUser user)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <ViewModelUser, User>());
            var mapper = new Mapper(config);

            UserRepo.AddUser(mapper.Map <User>(user));
        }
Example #4
0
        public Result UpsertUser(UserDto userDto)
        {
            try
            {
                if (userDto.Mode == EnumCrudMode.Create)
                {
                    UserRepo.AddUser(userDto);
                }
                else if (userDto.Mode == EnumCrudMode.Update)
                {
                    UserRepo.UpdateUser(userDto);
                }
                else if (userDto.Mode == EnumCrudMode.Delete)
                {
                    UserRepo.DeleteUser(userDto);
                }

                return(new Result()
                {
                    ResultCode = EnumResultCode.OK, Dto = userDto
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    ResultCode = EnumResultCode.Error, Details = ex.Message, Dto = userDto
                });
            }
        }
Example #5
0
        public void TestDeleteBacklogForUser()
        {
            var repo = new UserRepo(TestRootDir, UsersTestJson, g => 3);
            var user = new User {
                Id = 0, PasswordHash = "x", Username = "******", UserRole = UserRole.Guest
            };

            var status = repo.AddUser(user);

            status.Should().BeOfType <Success>();

            const string backlogId = "newrepoid";

            var addStatus = repo.AddUserBacklogId(3, backlogId);

            addStatus.Should().BeOfType <Success>();

            var(getStatus, backlogIds) = repo.GetUserBacklogIds(3);
            getStatus.Should().BeOfType <Success>();
            backlogIds.Contains(backlogId).Should().BeTrue();

            var deleteStatus = repo.DeleteUserBacklogId(3, backlogId);

            deleteStatus.Should().BeOfType <Success>();

            (getStatus, backlogIds) = repo.GetUserBacklogIds(3);
            getStatus.Should().BeOfType <Success>();
            backlogIds.Contains(backlogId).Should().BeFalse();
        }
Example #6
0
        public void TestAddUserSuccessful()
        {
            var user = new User {
                Id = 0, PasswordHash = "abc", Username = "******", UserRole = UserRole.Guest
            };
            var expectedUser = new User {
                Id = 3, PasswordHash = "abc", Username = "******", UserRole = UserRole.Guest
            };
            var repo = new UserRepo(TestRootDir, UsersTestJson, g => 3);

            var status = repo.AddUser(user);

            status.Should().BeOfType <Success>();

            var(status1, userList) = repo.GetExistingUsers();
            status1.Should().BeOfType <Success>();
            userList.FirstOrDefault(p => p.Id == 3).Should().BeEquivalentTo(expectedUser);

            var userDirectory = Path.Combine(TestRootDir, UsersDirectoryName, user.Id.ToString());

            Directory.Exists(userDirectory).Should().BeTrue();

            var backlogsFile = Path.Combine(userDirectory, UserBacklogsFileName);

            File.Exists(backlogsFile).Should().BeTrue();
        }
Example #7
0
        public void TestAddUserFailedAlreadyExists()
        {
            string result = null;
            var    user   = new User {
                Id = 1, PasswordHash = "x", Username = "******", UserRole = UserRole.Guest
            };
            var repo = new UserRepo(TestRootDir, UsersTestJson, g => 3);

            repo.AddUser(user, () => {}, s => { result = s; });

            Assert.AreEqual("User already exists", result);
        }
Example #8
0
        public void TestAddUserFailedAlreadyExists()
        {
            var user = new User {
                Id = 1, PasswordHash = "x", Username = "******", UserRole = UserRole.Guest
            };
            var repo = new UserRepo(TestRootDir, UsersTestJson, g => 3);

            var status = repo.AddUser(user);

            status.Should().BeOfType <Failure>();
            ((Failure)status).ErrorMessage.Should().NotBeNullOrEmpty();
        }
        public dynamic AddUer(UserModel model)
        {
            try
            {
                IUser _user = new UserRepo();

                _user.AddUser(model);
                return(null);
            }
            catch (Exception e)
            {
            }
            return(null);
        }
        public async Task <IActionResult> Post([FromBody] User user)
        {
            try
            {
                var id = await UserRepo.AddUser(user);

                User model = await UserRepo.GetUserAsync(id);

                return(CreatedAtRoute("Get", new { Id = id }, model));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #11
0
        public void AddUser(RegisterInputModel model)
        {
            var user = new User
            {
                Email            = model.Email,
                FullName         = model.FirstName + " " + model.LastName,
                Image            = model.Image,
                Address          = model.Address,
                Country          = model.Country,
                Postal           = model.Postal,
                FavoriteBookById = 0
            };

            _userRepo.AddUser(user);
        }
Example #12
0
        public ActionResult UserRegister(UserModel user)
        {
            var UserRegistered = new User()
            {
                Name      = user.Name,
                SurName   = user.SurName,
                Transfers = user.Transfers,
                Username  = user.Username,
                Password  = user.Password,
                Email     = user.Email
            };

            UserRepo.AddUser(UserRegistered);

            return(RedirectToAction("Index"));
        }
        private void confirmButtonRegistrationForm_Click(object sender, EventArgs e)
        {
            int isSuccessful = 0;

            if (userNameRegistrationForm.Text == string.Empty || emailRegistrationForm.Text == string.Empty ||
                phoneRegistrationForm.Text == string.Empty || passwordUserRegistrationForm.Text == string.Empty ||
                ageRegistrationForm.Text == string.Empty || houseNumberRegistrationForm.Text == string.Empty ||
                roadNumberRegistrationForm.Text == string.Empty || subDistrictRegistrationForm.Text == string.Empty ||
                districtRegistrationForm.Text == string.Empty || countryRegistrationForm.Text == string.Empty ||
                zipCodeRegistrationForm.Text == string.Empty || bloodGroupRegistrationForm.SelectedIndex == 0)
            {
                MetroMessageBox.Show(this, "Please Insert All The Values", "Some Field Left Unfilled", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }

            else
            {
                var addressDetails = new AddressInfo();
                var userDetails    = new UserInfo();
                var userToAdd      = new UserRepo();


                userDetails.Name      = userNameRegistrationForm.Text;
                userDetails.Phone     = phoneRegistrationForm.Text;
                userDetails.Email     = emailRegistrationForm.Text;
                userDetails.Age       = ageRegistrationForm.Text;
                userDetails.AddressId = 0;
                userDetails.BloodId   = bloodGroupRegistrationForm.SelectedIndex;
                userDetails.UserRole  = Convert.ToInt32("2"); //assigning general role as a normal user
                userDetails.Password  = passwordUserRegistrationForm.Text;
                userDetails.Date      = DateTime.Now;


                addressDetails.Houseno     = houseNumberRegistrationForm.Text;
                addressDetails.Roadno      = roadNumberRegistrationForm.Text;
                addressDetails.SubDistrict = subDistrictRegistrationForm.Text;
                addressDetails.District    = districtRegistrationForm.Text;
                addressDetails.Country     = countryRegistrationForm.Text;
                addressDetails.Zip         = Convert.ToInt32(zipCodeRegistrationForm.Text);

                isSuccessful = userToAdd.AddUser(userDetails, addressDetails); //user repo bll
                if (isSuccessful > 0)
                {
                    MetroMessageBox.Show(this, "Registration Successful Please go to the Login Page to login, Thank You", "Success", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    ClearForm();
                }
            }
        }
Example #14
0
        public void TestAddUserSuccessful()
        {
            string result   = null;
            var    userList = new List <User>();
            var    user     = new User {
                Id = 0, PasswordHash = "abc", Username = "******", UserRole = UserRole.Guest
            };
            var expectedUser = new User {
                Id = 3, PasswordHash = "abc", Username = "******", UserRole = UserRole.Guest
            };
            var repo = new UserRepo(TestRootDir, UsersTestJson, g => 3);

            repo.AddUser(user, () => result = "success", s => { });

            Assert.AreEqual("success", result);
            result = null;
            repo.GetExistingUsers(users => userList = users.ToList(), error => result = error);
            Assert.IsNull(result);
            userList.FirstOrDefault(p => p.Id == 3).Should().BeEquivalentTo(expectedUser);
        }
Example #15
0
        public async Task <ActionResult> Create(AddUserVM model)
        {
            // If success then proceed
            if (ModelState.IsValid)
            {
                // If the method returns true from user repo, do this
                if (_userRepo.AddUser(model, out string msg, out string userId))
                {
                    // Generate the email confirmation code for the user being generated
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(userId);

                    // Generating the call back url which will be sent to the user for confirmation
                    var callbackUrl = Url.Action("ConfirmEmail", "User", new { userId = userId, code = code }, protocol: Request.Url.Scheme);

                    // This is the content for the body of confirmation email message
                    string body = "Welcome to Notification Portal. In order to get started, you need to confirm your email address.";

                    // Send the confirmation email with TemplateService -> AccountEmail method
                    await UserManager.SendEmailAsync(userId, "Confirm your account", TemplateService.AccountEmail(callbackUrl, body, "Confirm Email"));

                    TempData["SuccessMsg"] = msg;
                    return(RedirectToAction("Index"));
                }
                TempData["ErrorMsg"] = msg;
            }

            // Load the dropdown / selectlistrepo values if adding the user fails
            model = _userRepo.CreateAddUserVM(model);
            // if model returns null, redirect to index
            if (model == null)
            {
                TempData["ErrorMsg"] = "Cannot create new user at the moment";
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Example #16
0
 public void Post(User value)
 {
     repo.AddUser(value);
 }
Example #17
0
 public void Post(UserDetail value)
 {
     repo.AddUser(value);
 }
Example #18
0
 public void AddUser(User user)
 {
     userRepo.AddUser(user);
 }
Example #19
0
 public ActionResult Register(string username, string password)
 {
     userMgr.AddUser(username, password);
     SetupFormsAuthTicket(username);
     return(RedirectToAction("Index"));
 }
        public void ClaimAccount()
        {
            commands.CreateCommand("ClaimAccount")
            .Parameter("Region", ParameterType.Required)
            .Parameter("Summoner", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string returnmessage = "An error happened.";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    RiotSharp.Region region = LeagueAndDatabase.GetRegionFromString(e.GetArg("Region"));
                    string summonername     = e.GetArg("Summoner");
                    SummonerRepo sumRepo    = new SummonerRepo(new SummonerContext());
                    UserRepo userRepo       = new UserRepo(new UserContext());
                    long riotid             = Convert.ToInt32(new SummonerAPI().GetSummonerId(summonername, region));
                    string token            = new StringBuilder().CreateToken();
                    if (
                        sumRepo.IsSummonerInSystem(riotid
                                                   ) == false
                        )
                    {
                        try
                        {
                            userRepo.GetUserIdByDiscord((e.User.Id));
                        }
                        catch
                        {
                            userRepo.AddUser(Convert.ToInt64(e.User.Id));
                        }
                        sumRepo.AddSummoner(userRepo.GetUserIdByDiscord((e.User.Id)), riotid,
                                            new RegionContext().GetRegionId(region), token);
                        returnmessage =
                            Eng_Default.RenameMasteryPage(
                                sumRepo.GetToken(userRepo.GetUserByDiscord((e.User.Id)), riotid).ToString());
                    }
                    else
                    {
                        returnmessage =
                            Eng_Default.RenameMasteryPageLong(
                                sumRepo.GetToken(userRepo.GetUserByDiscord((e.User.Id)), riotid));
                        string token2 = sumRepo.GetToken(userRepo.GetUserByDiscord((e.User.Id)), riotid);
                        foreach (var page in new SummonerAPI().GetSummonerMasteryPages(summonername, region))
                        {
                            if (page.Name.ToLower() == token2.ToLower())
                            {
                                sumRepo.VerifySummoner(userRepo.GetUserByDiscord((e.User.Id)), riotid);
                                returnmessage = Eng_Default.AccountVerified();
                                new RoleManagementCommands(BotUser, commands).GetRoles(e.Server, e.User);
                                new FlairTrigger(BotUser, commands).CreateFlair(new SummonerAPI().GetSummoner(riotid, region));
                            }
                        }
                        foreach (var page in new SummonerAPI().GetRunePages(summonername, region))
                        {
                            if (page.Name.ToLower() == token2.ToLower())
                            {
                                sumRepo.VerifySummoner(userRepo.GetUserByDiscord((e.User.Id)), riotid);
                                returnmessage = Eng_Default.AccountVerified();
                                new RoleManagementCommands(BotUser, commands).GetRoles(e.Server, e.User);
                                new FlairTrigger(BotUser, commands).CreateFlair(new SummonerAPI().GetSummoner(riotid, region));
                            }
                        }
                    }
                }
                else
                {
                    returnmessage = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnmessage);
            });
        }
Example #21
0
 public void AddUser(RegisterInputModel model, string id)
 {
     _userRepo.AddUser(model, id);
 }
Example #22
0
        public static User CreateNewUser(IEnumerable <Users> UserList, UserRepo userRepo)
        {
            logger.Info("Begin CreateNewUser method");
            bool   NewUsername = false;
            string Username    = "";

            while (!NewUsername)
            {
                Console.WriteLine("Welcome! Please enter a new username:"******"Username taken. Please select a different username.");
                }
                else
                {
                    NewUsername = true;
                }
            }

            Console.WriteLine("Please enter your first name:");
            string First = Console.ReadLine();

            Console.WriteLine("Please enter your last name:");
            string Last = Console.ReadLine();

            Console.WriteLine("Please enter a phone number we can contact:");
            string Phone = Console.ReadLine();

            Console.WriteLine("Please enter an email address we can contact:");
            string Email = Console.ReadLine();

            Console.WriteLine("We only deliver within Virginia! Please enter your full address (city included):");
            string Address = Console.ReadLine();

            bool   ValidFavorite = false;
            string Favorite      = "";

            Console.WriteLine("Which store would you like to mark as your favorite?");
            while (!ValidFavorite)
            {
                Console.WriteLine("Available stores: Reston, Herndon, Dulles, Hattontown");
                Favorite = Console.ReadLine().ToLower();

                if (Favorite != "reston" && Favorite != "herndon" && Favorite != "dulles" && Favorite != "hattontown")
                {
                    Console.WriteLine("Please input a valid favorite location.");
                }
                else
                {
                    ValidFavorite = true;
                }
            }

            Console.WriteLine("Excellent! We have all of your information!");
            logger.Info("Creating User object");


            User NewUser = new User(Username, First, Last, Phone, Email, Address, Favorite);

            logger.Info("New User Created");

            userRepo.AddUser(NewUser);

            return(NewUser);
        }
        private void MTRbtnSave_Click(object sender, EventArgs e)
        {
            bool       valid = true;
            Validation v     = new Validation(this);

            if (v.IsIdValid(this.MTRtxtFirstId.Text) == true)
            {
                DataAccess da  = new DataAccess();
                DataSet    ds  = new DataSet();
                string     sql = "select * from [HealthyHome].[dbo].[Health] where userId='" + this.MTRtxtFirstId.Text + "'";
                try
                {
                    ds = da.ExecuteQuery(sql);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);
                }
                if (ds.Tables[0].Rows.Count < 1)
                {
                    this.Id = this.MTRtxtFirstId.Text;
                }
                else
                {
                    valid = false;
                }
            }

            else if (MTRtxtFirstId.Text.Length == 0 || v.IsIdValid(this.MTRtxtFirstId.Text) == false)
            {
                MessageBox.Show("Please Fill ID ");
                valid = false;
            }


            if (MTRtxtName.Text.Length > 0 || this.MTRtxtName.Text.Any(c => char.IsDigit(c)) == false)
            {
                this.Name = this.MTRtxtName.Text;
            }



            else
            {
                MessageBox.Show("Please Fill Name ");
                valid = false;
            }


            if (v.IsPasswordValid(this.MTRtxtPassword.Text) == true)
            {
                this.Password = this.MTRtxtPassword.Text;
            }
            else if (MTRtxtPassword.Text.Length == 0 || v.IsPasswordValid(this.MTRtxtPassword.Text) == false)
            {
                MessageBox.Show("Please Fill Password ");
                valid = false;
            }


            if (this.MTRtxtEmail.Text.Length > 0)
            {
                this.Email = this.MTRtxtEmail.Text;
            }
            else
            {
                MessageBox.Show("Please Fill Email ");
                valid = false;
            }


            if (v.IsPhoneNoValid(this.MTRtxtPhoneNo.Text) == true)
            {
                this.PhoneNo = this.MTRtxtPhoneNo.Text;
            }
            else if (this.MTRtxtPhoneNo.Text.Length == 0 || v.IsPhoneNoValid(this.MTRtxtPhoneNo.Text) == false)
            {
                MessageBox.Show("Please Fill Phone Number ");
                valid = false;
            }



            if (MTRrbMale.Checked == true)
            {
                this.Gender = MTRrbMale.Text.ToString();
            }
            else if (MTRrbFemale.Checked == true)
            {
                this.Gender = MTRrbFemale.Text.ToString();
            }
            else
            {
                MessageBox.Show("Please Select Gender ");
                valid = false;
            }
            this.DateOfBirth = this.MTRdtmDateOfBirth.Text;

            User u1 = new User();

            u1.Name = this.Name;
            u1.Id   = this.Id;

            u1.Password    = this.Password;
            u1.Email       = this.Email;
            u1.PhoneNo     = this.PhoneNo;
            u1.Gender      = this.Gender;
            u1.DateOfBirth = DateOfBirth;
            MessageBox.Show(DateOfBirth);
            if (valid == true)
            {
                UserRepo UR = new UserRepo();
                UR.AddUser(u1);
                MTRLogin mtrL = new MTRLogin();
                mtrL.Visible = true;
                this.Hide();
            }
            else if (valid == false)
            {
                MessageBox.Show("Invalid Data Entrty");
            }
        }
Example #24
0
        protected async Task ManageUserCollection()
        {
            var pmoUser1 = new PMUser
            {
                EmployeeId = "EP001",
                LastName   = "L1",
                FirstName  = "F1"
            };
            var pmoUser2 = new PMUser
            {
                EmployeeId = "EP002",
                LastName   = "L2",
                FirstName  = "F2"
            };
            var pmoUser3 = new PMUser
            {
                EmployeeId = "EP003",
                LastName   = "L3",
                FirstName  = "F3"
            };
            var pmoUser4 = new PMUser
            {
                EmployeeId = "E004",
                LastName   = "L4",
                FirstName  = "F4"
            };
            var pmoUser5 = new PMUser
            {
                EmployeeId = "EP005",
                LastName   = "L5",
                FirstName  = "F5"
            };

            using (var session = DocStore.OpenAsyncSession())
            {
                var userCollectionLock = await session.Query <UserCollectionLock>()
                                         .FirstOrDefaultAsync();

                if ((userCollectionLock == default) || (!userCollectionLock.IsUserCollectionAdded))
                {
                    var logger   = createUserLogger();
                    var userRepo = new UserRepo(session, logger);
                    var result   = await userRepo.AddUser(pmoUser1);

                    result = await userRepo.AddUser(pmoUser2);

                    result = await userRepo.AddUser(pmoUser3);

                    result = await userRepo.AddUser(pmoUser4);

                    result = await userRepo.AddUser(pmoUser5);

                    userCollectionLock = new UserCollectionLock {
                        IsUserCollectionAdded = true
                    };
                    await session.StoreAsync(userCollectionLock);

                    await session.SaveChangesAsync();
                }
            }
        }