public IActionResult Register(RegisterViewModel regModel)
        {
            int?isInSession = HttpContext.Session.GetInt32("user");

            if (isInSession == null)
            {
                if (ModelState.IsValid)
                {
                    PasswordHasher <RegisterViewModel> Hasher = new PasswordHasher <RegisterViewModel>();
                    User user = new User {
                        name        = regModel.name,
                        email       = regModel.email,
                        description = regModel.description,
                        password    = Hasher.HashPassword(regModel, regModel.password)
                    };
                    bool exists = userFactory.CheckUserInDB(user.email);
                    if (exists)
                    {
                        ViewBag.error = "This email is already registered. Please log in.";
                        return(View("Login"));
                    }
                    else
                    {
                        userFactory.AddUser(user);
                        User newUser = userFactory.GetCurrentUser(user.email);
                        // ViewBag.user = newUser;

                        HttpContext.Session.SetInt32("user", newUser.id);
                        return(RedirectToAction("Success"));
                    }
                }
                return(View("Register", regModel));
            }
            return(RedirectToAction("Success"));
        }
Пример #2
0
        public void UploadStudents(IFormFile students)
        {
            Stream fileStream = students.OpenReadStream();

            using (StreamReader reader = new StreamReader(fileStream))
            {
                while (!reader.EndOfStream)
                {
                    string   line = reader.ReadLine();
                    string[] data = line.Split(',');
                    User     u    = new User {
                        FirstName     = data[0],
                        LastName      = data[1],
                        Email         = data[2],
                        Password      = data[3],
                        AccessLevelId = Convert.ToInt16(data[4])
                    };
                    int uId = _userFactory.AddUser(u);

                    Student s = new Student {
                        UserId      = uId,
                        StartDate   = Convert.ToDateTime(data[5]),
                        CurrStackId = Convert.ToInt16(data[7])
                    };
                    if (data[6] != "")
                    {
                        s.EndDate = Convert.ToDateTime(data[6]);
                    }
                    _userFactory.AddStudent(s);
                }
            }
        }
Пример #3
0
        public IActionResult Register(User NewUser)
        {
            if (ModelState.IsValid)
            {
                System.Console.WriteLine("CLEAN: INPUTS VALID");

                //ADD USER
                System.Console.WriteLine(NewUser.Password);
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password);
                System.Console.WriteLine(NewUser.Password);
                userFactory.AddUser(NewUser);

                // GET USER
                ViewBag.user = userFactory.GetUser(NewUser.Email);

                return(View("Success"));
            }
            else
            {
                System.Console.WriteLine("ERROR: INPUTS INVALID");
                ViewBag.errors  = ModelState.Values;
                ViewBag.lerrors = "";
                return(View("Index"));
            }
        }
Пример #4
0
 public IActionResult RegisterUser(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (userFactory.GetUserByEmail(model.Email) == null)
         {
             User newuser = new User {
                 FirstName = model.FirstName,
                 LastName  = model.LastName,
                 Email     = model.Email,
                 Password  = model.Password
             };
             PasswordHasher <User> Hasher = new PasswordHasher <User>();
             newuser.Password = Hasher.HashPassword(newuser, newuser.Password);
             userFactory.AddUser(newuser);
         }
         else
         {
             ViewBag.EmailError = "Email taken";
             return(View("Register"));
         }
     }
     else
     {
         return(View("Register"));
     }
     return(Redirect("/"));
 }
Пример #5
0
        internal string AddNewUser(string[] fileData)
        {
            string help = "Add a new temporary user to the server, this user will not be stored once the server closes.\n" +
                          "Only the admin can create a new user\n\n" +
                          $"Syntax: admin addnewuser <newuserID> <newuserPassword>\n" +
                          $"   e.g. admin addnewuser owen steele\n\n" +
                          $"This creates a new user, to login to this user as a client:\n" +
                          $"& login\n" +
                          $"user: owen\n" +
                          $"password: steele\n\n" +
                          $"A new user has by default basic-elevated privileges.";

            if (fileData.Length < 4)
            {
                return(help);
            }
            string[] details = { fileData[2], fileData[3] };

            if (UserFactory.AddUser(details))
            {
                return("New user added successfully.");
            }
            else
            {
                return("Error new user could not be added.");
            }
        }
Пример #6
0
 public IActionResult Register(RegisterUser NewUser)
 {
     if (ModelState.IsValid)
     {
         PasswordHasher <User> Hasher = new PasswordHasher <User>();
         NewUser.password = Hasher.HashPassword(NewUser, NewUser.password);
         ModelState.AddModelError("Registration", userFactory.AddUser(NewUser));
         ViewBag.errors = ModelState.Values;
         return(View("Index"));
     }
     ViewBag.errors = ModelState.Values;
     return(View("Index"));
 }
Пример #7
0
 public IActionResult RegisterUser(User model)
 {
     if (ModelState.IsValid)
     {
         PasswordHasher <User> Hasher = new PasswordHasher <User>();
         model.password = Hasher.HashPassword(model, model.password);
         userfactory.AddUser(model);
         ViewBag.Errors = "Account Created Procede to Log in";
         return(RedirectToAction("LogRegPage"));
     }
     ViewBag.Errors = ModelState.Values;
     return(RedirectToAction("LogRegPage"));
 }
Пример #8
0
 public IActionResult Add(UserModel model)
 {
     using (var userService = new UserFactory(_serviceOptions).Build())
     {
         try
         {
             var user = userService.AddUser(_mapper.Map <User>(model));
             return(Ok(_mapper.Map <UserModel>(user)));
         }
         catch (Exception ex)
         {
             return(StatusCode(500, ex.Message));
         }
     }
 }
Пример #9
0
        public JsonResult SaveUser(string guid = "")
        {
            string userName = Request["userName"].ToString();
            string realName = Request["realName"].ToString();
            string phoneNum = Request["phoneNum"].ToString();
            string roles    = Request["roles"].ToString();

            if (string.IsNullOrWhiteSpace(guid))
            {
                _userFactory.AddUser(userName, realName, phoneNum, roles);
            }
            else
            {
                _userFactory.SaveUser(guid, userName, realName, phoneNum, roles);
            }
            return(Json(new { result = 1 }));
        }
Пример #10
0
 public IActionResult NewUser(User T, string passConf)
 {
     if (ModelState.IsValid)
     {
         if (T.Password != passConf)
         {
             return(RedirectToAction("Index"));
         }
         PasswordHasher <User> Hasher = new PasswordHasher <User>();
         T.Password = Hasher.HashPassword(T, T.Password);
         string pass = T.Password;
         System.Console.WriteLine(pass);
         _userfactory.AddUser(T, pass);
         return(RedirectToAction("Index"));
     }
     return(View("Index"));
 }
Пример #11
0
        public IActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Message"] = "Something went wrong, please try again";
                return(View("Index"));
            }
            PasswordHasher <User> hasher = new PasswordHasher <User>();

            Models.User user = new User
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Email     = model.Email,
            };
            user.Password = hasher.HashPassword(user, model.Password);
            _userFactory.AddUser(user);
            HttpContext.Session.SetInt32("Id", _userFactory.GetUserByEmail(model.Email).Id);
            return(RedirectToAction("Index"));
        }
Пример #12
0
 public IActionResult Register(RegisterUser NewUser)
 {
     if (HttpContext.Session.GetString("loggedIn") == "true")
     {
         ViewBag.loggedIn = true;
     }
     else
     {
         ViewBag.loggedIn = false;
     }
     if (ModelState.IsValid)
     {
         PasswordHasher <User> Hasher = new PasswordHasher <User>();
         NewUser.password = Hasher.HashPassword(NewUser, NewUser.password);
         ModelState.AddModelError("Registration", userFactory.AddUser(NewUser));
         ViewBag.errors = ModelState.Values;
         return(View("Index"));
     }
     ViewBag.errors = ModelState.Values;
     return(View("Index"));
 }
Пример #13
0
        private async Task <dynamic> AddUser(dynamic parameters)
        {
            var   newUser = this.Bind <User>();
            Utils utils   = new Utils(newUser);

            if (!(newUser.FirstName != null && newUser.FirstName.Length > 0))
            {
                utils.CommandSucceeded = false;
                utils.AddMessage("FirstName is a required field.<br />");
            }
            if (!(newUser.LastName != null && newUser.LastName.Length > 0))
            {
                utils.CommandSucceeded = false;
                utils.AddMessage("LastName is a required field.<br />");
            }
            if (!(newUser.Email != null && newUser.Email.Length > 0))
            {
                utils.CommandSucceeded = false;
                utils.AddMessage("Email is a required field.<br />");
            }
            else if (!(utils.emailIsValid(newUser.Email)))
            {
                utils.CommandSucceeded = false;
                utils.AddMessage("Email is not a valid format.<br />");
            }

            if (utils.CommandSucceeded)
            {
                UserFactory uf = new UserFactory();

                dynamic x = await uf.AddUser(newUser);

                return(ListUsers());
            }
            else
            {
                utils.User = newUser;
                return(View["AddUser", utils]);
            }
        }
Пример #14
0
        public IActionResult Register(User NewUser)
        {
            if (ModelState.IsValid)
            {
                System.Console.WriteLine("ModelState is valid");

                // Add User
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password);
                userFactory.AddUser(NewUser);
                // Get Added User
                User CurrentUser = userFactory.GetLastUser();
                HttpContext.Session.SetInt32("CurrUserId", CurrentUser.UserId);

                return(RedirectToAction("Wall"));
            }
            else
            {
                System.Console.WriteLine("ERRORS: Validations triggered");
                ViewBag.Errors    = ModelState.Values;
                ViewBag.LogErrors = new List <User>();
                return(View("Index"));
            }
        }