示例#1
0
        /// <summary>
        /// Used to Create a User Model
        /// First insert into user
        /// then insert into auth
        /// if the first insert fail dont insert the pwd
        /// if second insert fails rollback
        /// </summary>
        /// <remarks>Uses Transactions</remarks>
        /// <param name="user"></param>
        public static void CreateAccount(RegistrationUserModel user)
        {
            const string sql1 = "insert into users values(@email,@firstname,@familyname)";
            const string sql2 = "insert into auth values(@email,@pwd)";
            var          par1 = new DynamicParameters();

            par1.Add("email", user.Email);
            par1.Add("firstname", user.FirstName);
            par1.Add("familyname", user.FamilyName);
            var par2 = new DynamicParameters();

            par2.Add("email", user.Email);
            par2.Add("pwd", HashPassword(user.Password).Trim());
            //Using a transaction to perform the insert into two tables
            //In case of an Error rollback
            using (var transcope = new TransactionScope())
            {
                if (DapperORM.ExecuteInsert(sql1, par1) > 0)
                {
                    if (DapperORM.ExecuteInsert(sql2, par2) < 0)
                    {
                        transcope.Dispose();
                    }
                }

                transcope.Complete();
            }
        }
示例#2
0
        public IHttpActionResult Register([FromBody] RegistrationUserModel user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                AccountBll.CreateAccount(user);
                var status = new MessageStatus()
                {
                    Code    = "200",
                    Message = "User was Created Succesfully"
                };
                return(Content(HttpStatusCode.OK, status, new JsonMediaTypeFormatter()));
            }
            catch (Exception e)
            {
                var status = new MessageStatus
                {
                    Code    = "500",
                    Message = e.Message
                };
                return(Content(HttpStatusCode.BadRequest, status, new JsonMediaTypeFormatter()));
            }
        }
示例#3
0
        public async Task <ActionResult <ReturnUserDTO> > Register(RegistrationUserModel user)
        {
            if (user == null)
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(user));
            }

            var registrationUser = mapper.Map <ApplicationUser>(user);
            var result           = await userManager.CreateAsync(registrationUser, user.Password);

            if (!result.Succeeded)
            {
                return(BadRequest("Registration not success"));
            }
            else
            {
                await userManager.AddToRoleAsync(registrationUser, "User");

                string JWT_token = GenerateJWT(user.UserName, "User");

                ReturnUserDTO returnUser = mapper.Map <ReturnUserDTO>(registrationUser);
                returnUser.Token = JWT_token;
                return(returnUser);
            }
        }
示例#4
0
        public IActionResult RegisterUser([FromBody] RegistrationUserModel user)
        {
            try
            {
                RUserModel responseUser = null;

                if (!user.Equals(null))
                {
                    responseUser = userBL.RegisterUser(user);
                }
                else
                {
                    throw new Exception(UserExceptions.ExceptionType.INVALID_ROLE_EXCEPTION.ToString());
                }

                if (responseUser != null)
                {
                    bool Success = true;
                    var  Message = "Registration Successfull";
                    return(Ok(new { Success, Message, Data = responseUser }));
                }
                else
                {
                    bool Success = false;
                    var  Message = "User Already Exists";
                    return(Conflict(new { Success, Message }));
                }
            }
            catch (Exception exception)
            {
                bool Success = false;
                return(BadRequest(new { Success, Message = exception.Message }));
            }
        }
        public ActionResult Registration(RegistrationUserModel temp, bool captchaValid, string captchaErrorMessage)
        {
            if (ModelState.IsValid)
            {
                if (!captchaValid)
                {
                    ModelState.AddModelError("recaptcha", captchaErrorMessage);
                    return(View(temp));
                }
                user newUser = new user();
                newUser.login    = temp.login;
                newUser.password = Crypto.HashPassword(temp.password);
                newUser.admin    = false;
                newUser.email    = temp.email;

                if (dbUser.addUser(newUser))
                {
                    return(RedirectToAction("LogIn", "User"));
                }

                ModelState.AddModelError("", "Login or email address is already taken");
            }

            return(View(temp));
        }
        public ActionResult RegistrationDB(RegistrationUserModel user)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Error = null;
                return(View("Registration", user));
            }

            _context.NWUsers.Add(new UserModel
            {
                Username   = user.Username,
                Firstname  = user.Firstname,
                Lastname   = user.Lastname,
                Password   = Hash(user.Password),
                Email      = user.Email,
                Permission = (from x in _context.Permissions where x.Name.Equals("member") select x).FirstOrDefault(),
                Style      = (from x in _context.Styles where x.Name.Equals("light") select x).FirstOrDefault()
            });
            _context.SaveChanges();

            return(RedirectToAction("Login"));

            //if (db.InsertUser(user))
            //{
            //    ViewBag.Error = null;
            //    return RedirectToAction("Login");
            //}
            //else
            //{
            //    ViewBag.Error = "Adatbázis hiba történt!";
            //    return View("Registration");
            //}
        }
        public ActionResult Register(RegistrationUserModel registrationUserModel)
        {
            if (string.IsNullOrEmpty(registrationUserModel.User.Email))
            {
                ModelState.AddModelError("User.Email", "Please enter your email address");
            }

            if (_userManager.IsUserRegistered(registrationUserModel.User.Username))
            {
                ModelState.AddModelError("User.Username", string.Format("{0} already registered", registrationUserModel.User.Username));
            }

            if (ModelState.IsValid)
            {
                tblUsers user = new tblUsers()
                {
                    UserName         = registrationUserModel.User.Username,
                    Password         = registrationUserModel.User.Password,
                    RegistrationDate = DateTime.Now,
                    Email            = registrationUserModel.User.Email
                };

                bool isSuccesful = _userManager.InsertUser(user);

                return(isSuccesful ? View("SuccessfullRegistration", registrationUserModel) : View("RegistrationFailed"));
            }

            return(View());
        }
示例#8
0
        public void FillLoginForm(RegistrationUserModel user)
        {
            Type(this.Email, user.Email);
            Type(this.Password, user.Password);

            this.LoginButton.Click();
        }
示例#9
0
 public void FillRegistrationForm(RegistrationUserModel user)
 {
     Type(this.FullName, user.FullName);
     Type(this.Email, user.Email);
     Type(this.Password, user.Password);
     Type(this.ConfirmPassword, user.ConfirmPassword);
     this.RegisterButton.Click();
 }
        public void SetUp()
        {
            Initialize();
            _automationPracticePage = new AutomationPracticePage(Driver);
            _automationPracticePage.NavigateTo();
            Driver.Manage().Window.Maximize();

            _automationPracticePage.LoginButton.Click();

            _user = UserFactory.Create();
        }
示例#11
0
 private RUserModel DataCopy(RUserModel usermodel, RegistrationUserModel user)
 {
     usermodel.FirstName    = user.FirstName;
     usermodel.LastName     = user.LastName;
     usermodel.EmailId      = user.EmailId;
     usermodel.Gender       = user.Gender;
     usermodel.LocalAddress = user.LocalAddress;
     usermodel.MobileNumber = user.MobileNumber;
     usermodel.Role         = user.Role;
     return(usermodel);
 }
示例#12
0
 /// <summary>
 /// Function For Register User.
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public RUserModel RegisterUser(RegistrationUserModel user)
 {
     try
     {
         return(this.userRL.RegisterUser(user));
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
示例#13
0
        public ActionResult Register()
        {
            if (Request.IsAuthenticated)
            {
                return(View("/Home/Index"));
            }
            RegistrationUserModel model = new RegistrationUserModel();

            model.DropDownItems = model.getCountry();
            return(View("Index", model));
        }
示例#14
0
        public async Task <IActionResult> Register(RegistrationUserModel model)
        {
            var accountUser = _mapper.Map <AccountUser>(model);

            try
            {
                var result = await _userManager.CreateAsync(accountUser, model.Password);

                await _userManager.AddToRoleAsync(accountUser, model.Role);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#15
0
        public async Task <IActionResult> Registration([FromBody] RegistrationUserModel user)
        {
            if (ModelState.IsValid)
            {
                var token = await _userServices.Registrate(_mapper.Map <RegistrationUserBLL>(user));

                if (token == null)
                {
                    BadRequest();
                }
                return(Ok(token));
            }
            else
            {
                return(BadRequest());
            }
        }
示例#16
0
        public void Test_User_Is_Registered()
        {
            AccountController     controller = new AccountController();
            string                randomchar = Util.GenerateRandomChar();
            RegistrationUserModel model      = new RegistrationUserModel();

            model.Email      = randomchar + "@gmail.com";
            model.FamilyName = randomchar;
            model.FirstName  = randomchar;
            model.Password   = randomchar;
            IHttpActionResult result = controller.Register(model);
            var contentresult        = result as FormattedContentResult <MessageStatus>;

            Assert.IsNotNull(result);
            Assert.IsNotNull(contentresult.Content.Code);
            Assert.IsNotNull(contentresult.Content.Message);
            Assert.AreEqual("200", contentresult.Content.Code);
        }
        public async Task <HttpResponseMessage> RegisterUser(RegistrationUserModel values)
        {
            try
            {
                var content = new StringContent(JsonConvert.SerializeObject(values));

                using (var client = new HttpClient())
                {
                    content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
                    var result = await client.PostAsync(Uri + "/api/v1/Registration", content);

                    return(result);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#18
0
        public async Task <StatusCodeResult> Registration([FromBody] RegistrationUserModel model)
        {
            var user = await _usersRepository.GetUserByLogin(model.Name, model.Password);

            if (user == null)
            {
                var result = await _usersRepository.AddUser(model.Name, model.Password, false);

                if (result)
                {
                    return(new OkResult());
                }
                else
                {
                    return(new BadRequestResult());
                }
            }

            return(new BadRequestResult());
        }
示例#19
0
        public void FillForm(RegistrationUserModel user)
        {
            //Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(6);
            ValidateFirstNameField.Click();
            ValidateFirstNameField.SendKeys(user.FirstName + Keys.Tab);
            Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            ScrollTo(ValidateLastNameField).Click();
            ValidateLastNameField.SendKeys(user.LastName + Keys.Tab);
            ValidateEnteredEmailField.Click();
            ValidatePasswordField.SendKeys(user.Password);
            ValidateAddressField.SendKeys(user.Address);
            ValidateCityField.SendKeys(user.City);
            SelectElement state = new SelectElement(ValidateStateField);

            state.SelectByValue("1");
            ValidateZipField.SendKeys(user.Zip);
            ValidateCountryField.SendKeys(user.Country);
            ValidateMobilePhoneField.SendKeys(user.MobilePhone);
            ValidateAliasAddressField.SendKeys(user.AliasAddress + Keys.Tab);
            RegistrationButton.Click();
        }
示例#20
0
        public async Task CreateUserAsync(RegistrationUserModel registrationUserModel)
        {
            var user = await _userRepository.GetAsync(u => u.UserName == registrationUserModel.UserName);

            if (user != null)
            {
                throw new Exception("Such user exist!");
            }

            var newUser = new UserInfoEntity
            {
                UserName     = registrationUserModel.UserName,
                FirstName    = registrationUserModel.FirstName,
                LastName     = registrationUserModel.LastName,
                Email        = registrationUserModel.Email,
                DateOfBirth  = registrationUserModel.DateOfBirth,
                PhoneNumber  = registrationUserModel.PhoneNumber,
                PasswordHash = registrationUserModel.Password,
                Role         = registrationUserModel.UserRole
            };

            await _userRepository.InsertAsync(newUser);
        }
示例#21
0
        public void Test_user_Login()
        {
            AccountController     controller = new AccountController();
            string                randomchar = Util.GenerateRandomChar();
            RegistrationUserModel model      = new RegistrationUserModel();

            model.Email      = randomchar + "@gmail.com";
            model.FamilyName = randomchar;
            model.FirstName  = randomchar;
            model.Password   = randomchar;
            controller.Register(model);
            var            controller2 = CreatePost("account");
            UserLoginModel loginModel  = new UserLoginModel {
                Email = model.Email, Password = model.Password
            };
            var result2       = controller2.Login(loginModel);
            var contentresult = result2 as FormattedContentResult <Dictionary <string, string> >;

            Assert.IsNotNull(result2);
            Assert.IsNotNull(contentresult.Content);
            //token not null
            Assert.IsNotNull(contentresult.Content["token"]);
        }
示例#22
0
        //POST : api/RegistrationUser/Register
        public async Task <Object> PostRegistrationUser(RegistrationUserModel model)
        {
            model.Role = "Admin";
            var registrationUser = new RegistrationUser()
            {
                UserName    = model.UserName,
                FullName    = model.FullName,
                Email       = model.Email,
                PhoneNumber = model.PhoneNumber,
            };

            try
            {
                var result = await _usermanger.CreateAsync(registrationUser, model.Password);

                await _usermanger.AddToRoleAsync(registrationUser, model.Role);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#23
0
        public ActionResult Register(RegistrationUserModel model)
        {
            //time for some inefficiant error checking - needs to be made better
            SmartService smartService = new SmartService();

            ViewBag.DisplayItems = true;

            if (model.password != model.confirm)
            {
                ModelState.AddModelError("confirm", "Your passwords don't match. Please retype your passwords and try again");
            }
            if (!model.tandc)
            {
                ModelState.AddModelError("tandc", "You must tick the Terms & Conditions checkbox to register.");
            }

            if (ModelState.IsValid)
            {
                //build account object and pass to insert registration.

                var  sales        = Request.Form["sales"];
                bool emailservice = (sales == null) ? false : true;

                AccountType at   = new AccountType();
                string      hash = smartService.GetMd5Hash(MD5.Create(), model.password);
                at.username     = model.email;
                at.password     = hash;
                at.firstname    = model.firstname;
                at.surname      = model.lastname;
                at.email        = model.email;
                at.jobTitle     = model.jobtitle;
                at.organisation = model.organization;
                at.telephone    = model.number;
                at.emailService = model.sales;
                at.country      = model.country;

                at.address = model.address;
                at.emailServiceSpecified = true;

                at.emailService = emailservice;

                TermType tt0 = new TermType();
                at.areasOfInterest = new TermType[] { tt0 };

                string key, toHash, token;
                token = smartService.AuthToken();
                if (token == "")
                {
                }
                else
                {
                    // Create a validation key based on the authentication token
                    toHash = token;
                    key    = smartService.GetMd5Hash(MD5.Create(), toHash);
                    try
                    {
                        TempData["Message"] = smartService.InsertAccount(key, at);
                        return(Login(new User()
                        {
                            UserName = model.email, Password = model.password
                        }, "", ""));
                    }
                    catch (SoapException se)
                    {
                        var msg = se.Detail["ErrorMessage"]["errorMessage"].InnerText;
                        ModelState.AddModelError("Problem", msg);
                        if (msg.ToLower().Contains("account created pending verification"))
                        {
                            ViewBag.DisplayItems = false;
                        }
                    }
                    catch (Exception ex) // apparently not throwing the expected fault exception. handling argument exception instead.
                    {
                        TempData["Error"] = "Error Message: " + ex.Message;
                    }
                }
            }
            model.DropDownItems = model.getCountry();
            return(View("Index", model));
        }
示例#24
0
        /// <summary>
        /// Function For Register User.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>

        public RUserModel RegisterUser(RegistrationUserModel user)
        {
            try
            {
                //Throws Custom Exception When Fields are Null.
                if (user.FirstName == null || user.Role == null || user.Password == null || user.EmailId == null || user.LastName == null || user.Gender == null || user.LocalAddress == null || user.Password == null || user.MobileNumber == null)
                {
                    throw new Exception(UserExceptions.ExceptionType.NULL_EXCEPTION.ToString());
                }

                //Throws Custom Exception When Fields are Empty Strings.
                if (user.FirstName == "" || user.Role == "" || user.Password == "" || user.EmailId == "" || user.LastName == "" || user.Gender == "" || user.LocalAddress == "" || user.Password == "" || user.MobileNumber == "")
                {
                    throw new Exception(UserExceptions.ExceptionType.EMPTY_EXCEPTION.ToString());
                }

                if ((user.Role.Equals(Roles.Admin.ToString()) || user.Role.Equals(Roles.Driver.ToString()) ||
                     user.Role.Equals(Roles.Police.ToString()) || user.Role.Equals(Roles.Security.ToString()) ||
                     user.Role.Equals(Roles.Owner.ToString()) || user.Role.Equals(Roles.Attendant.ToString())))
                {
                    if (!EmailChecking(user.EmailId))
                    {
                        return(null);
                    }
                    int        status    = 0;
                    RUserModel usermodel = new RUserModel();
                    user.Password = Encrypt(user.Password).ToString();
                    SqlCommand sqlCommand = new SqlCommand("spUserRegistration", this.sqlConnectionVariable);
                    sqlCommand.CommandType = CommandType.StoredProcedure;

                    sqlCommand.Parameters.AddWithValue("@Firstname", user.FirstName);
                    sqlCommand.Parameters.AddWithValue("@Lastname", user.LastName);
                    sqlCommand.Parameters.AddWithValue("@EmailID", user.EmailId);
                    sqlCommand.Parameters.AddWithValue("@Role", user.Role);
                    sqlCommand.Parameters.AddWithValue("@UserPassword", user.Password);
                    sqlCommand.Parameters.AddWithValue("@CurrentAddress", user.LocalAddress);
                    sqlCommand.Parameters.AddWithValue("@MobileNumber", user.MobileNumber);
                    sqlCommand.Parameters.AddWithValue("@Gender", user.Gender);

                    this.sqlConnectionVariable.Open();

                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        status                = sqlDataReader.GetInt32(0);
                        usermodel.UserId      = Convert.ToInt32(sqlDataReader["UserId"]);
                        usermodel.DateAndTime = sqlDataReader["ModificationDate"].ToString();
                        if (status > 0)
                        {
                            return(DataCopy(usermodel, user));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    throw new Exception(UserExceptions.ExceptionType.INVALID_ROLE_EXCEPTION.ToString());
                }
                return(null);
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
        private async void RegistrationButton(object obj)
        {
            var boxes                   = (object[])obj;
            var passwordBox             = ((PasswordBox)boxes[0]);
            var passwordBoxConfirmation = (PasswordBox)boxes[1];

            if (!_validator.ValidatorEmail(Email))
            {
                ErrorLabel             = " Enter e-mail... Incorrect e-mail...";
                Email                  = "";
                IsRegisterButtonEnable = true;
                return;
            }

            if (!_validator.PasswordValidator(passwordBox.Password))
            {
                ErrorLabel                       = "Enter password... Passwords must be at least 8 characters and contain at 3 of 4 of the following: upper case (A-Z), lower case (a-z), number (0-9) and special character (e.g. !@#$%^&*)...";
                passwordBox.Password             = "";
                passwordBoxConfirmation.Password = "";
                IsRegisterButtonEnable           = true;
                return;
            }

            if (!_validator.ConfirmPassword(passwordBoxConfirmation.Password, passwordBox.Password))
            {
                ErrorLabel = "Incorrectly entered password...";
                PasswordBackGroundCollor        = "Red";
                ConfirmPasswordBackGroundCollor = "Red";
                IsRegisterButtonEnable          = true;
                return;
            }

            IsRegisterButtonEnable = false;

            var newUser = new RegistrationUserModel
            {
                UserName    = UserName,
                Email       = Email,
                Password    = passwordBox.Password,
                PhoneNumber = PhoneNumber,
                FirstName   = FirstName,
                LastName    = LastName,
                DateOfBirth = new DateTimeOffset(DataOfBirth),
                UserRole    = Role
            };



            var result = await _registrationManager.RegisterUser(newUser);

            if (result.IsSuccessStatusCode)
            {
                MessageBox.Show("You are successfully registered...", "Congratulations!", MessageBoxButton.OK,
                                MessageBoxImage.Information);
                var loginPage = new Authorization();
                loginPage.Show();
            }
            else
            {
                ErrorLabel             = "The login or email address you have already entered is already in use.";
                Email                  = "";
                passwordBox.Password   = "";
                IsRegisterButtonEnable = true;
                return;
            }
        }
示例#26
0
 public void CreateAccount(RegistrationUserModel user)
 {
     EmailFieldCreateAccount.SendKeys(user.Email);
     EmailFieldCreateAccount.Submit();
     CreateAccountButton.Click();
 }
        public async Task <IActionResult> RegistrationAsync([FromBody] RegistrationUserModel input)
        {
            await _userService.CreateUserAsync(input);

            return(Ok());
        }