예제 #1
0
        // GET: RegularUsers/Details/5
        public async Task <IActionResult> UserDetails()
        {
            UserViewModel view = new UserViewModel()
            {
                user = new RegularUser()
            };

            //var options = new PayoutCreateOptions
            //{
            //    Amount = 5000,
            //    Currency = "usd",
            //};
            //var service = new PayoutService();


            //Payout payout = service.Create(options);

            var         currentUser  = User.Identity.GetUserId();
            RegularUser RegularUsers = _context.RegularUsers.Where(s => s.ApplicationUserId == currentUser).SingleOrDefault();

            view.user = RegularUsers;
            var regularUser = await _context.RegularUsers
                              .Include(r => r.ApplicationUser)
                              .FirstOrDefaultAsync(m => m.ApplicationUserId == currentUser);

            if (regularUser == null)
            {
                return(NotFound());
            }
            return(View(view));
        }
예제 #2
0
        // GET: RegularUsers/Details/5
        public IActionResult Profiles(string id)
        {
            UserViewModel view = new UserViewModel()
            {
                message  = new Messages(),
                user     = new RegularUser(),
                follower = new Follower()
            };
            RegularUser RegularUsers = _context.RegularUsers.Where(s => s.ApplicationUserId == id).SingleOrDefault();

            view.user = RegularUsers;

            ViewData["Followers"] = _context.Followers.Count();

            //id = view.user.ApplicationUserId;
            if (id == null)
            {
                return(NotFound());
            }

            if (view.user == null)
            {
                return(NotFound());
            }

            return(View(view));
        }
예제 #3
0
    protected void UnLike(object sender, EventArgs e)
    {
        LikeBusiness lb  = new LikeBusiness();
        ModernButton btn = (ModernButton)sender;

        string[]    ids         = btn.ID.Split('_');
        RegularUser regularUser = new RegularUser();

        regularUser.UserId = Int32.Parse(ids[0]);

        Hike hike = new Hike();

        hike.HikeId = Int32.Parse(ids[1]);

        Tuple <int, string> t = new Tuple <int, string>(0, "");

        t = lb.removeLike(regularUser, hike);

        Notification n = new Notification();

        n.Type    = t.Item1;
        n.Message = t.Item2;
        Session["NOTIFICATION"] = n;
        Response.Redirect("Notifications.aspx");
        //Response.Redirect("Wall.aspx");
    }
예제 #4
0
    public Tuple <int, string> RemoveFriend(ref RegularUser user, ref RegularUser friend)
    {
        int    id;
        string message;

        switch (userData.RemoveFriend(user, friend))
        {
        case 0:
            id      = 1;
            message = "Ya no son amigos";
            break;

        case 1:
            id      = 2;
            message = "Amistad no existe";
            break;

        default:
            id      = 2;
            message = "Error al quitar una amistad. Contacte a un administrador";
            break;
        }

        Tuple <int, string> n = new Tuple <int, string>(id, message);

        return(n);
    }
예제 #5
0
        public async Task <IActionResult> RegisterUser(RegisterUserFormModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new RegularUser
                {
                    UserName         = model.Username,
                    Email            = model.Email,
                    FirstName        = model.FirstName,
                    LastName         = model.LastName,
                    Gender           = model.Gender,
                    RegistrationDate = DateTime.UtcNow.ToLocalTime()
                };

                var result = await this.userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    this.logger.LogInformation("User created a new account with password.");

                    var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user);

                    await this.signInManager.SignInAsync(user, isPersistent : false);

                    this.logger.LogInformation("User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            return(View(model));
        }
        private static void SeedUsers(ETicketSystemDbContext db, UserManager <User> userManager)
        {
            if (File.Exists(WebConstants.FilePath.Users))
            {
                var users = File.ReadAllText(WebConstants.FilePath.Users).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                for (int i = 1; i < users.Length; i++)
                {
                    var userInfo = users[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    var password = userInfo[4];
                    var username = userInfo[0];
                    var email    = userInfo[1];

                    var user = new RegularUser()
                    {
                        UserName  = username,
                        Email     = email,
                        FirstName = userInfo[2],
                        LastName  = userInfo[3]
                    };

                    Task.Run(async() =>
                    {
                        var userExists = await db.Users.AnyAsync(u => u.UserName.ToLower() == username.ToLower() && u.Email.ToLower() == email.ToLower());

                        if (!userExists)
                        {
                            await userManager.CreateAsync(user, password);
                        }
                    })
                    .Wait();
                }
            }
        }
예제 #7
0
        public async Task <ActionResult> RegisterRegular(RegisterRegularViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = new RegularUser {
                    UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName
                };
                var result = await this.UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await this.UserManager.AddToRoleAsync(user.Id, "Regular");

                    await this.SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    return(this.RedirectToAction("Index", "Home"));
                }

                this.AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(this.View(model));
        }
예제 #8
0
        public IList <RegularUser> RetrieveRegularUsers()
        {
            IList <RegularUser> regularUsersList = new List <RegularUser>();

            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                string statement = "SELECT * FROM regularuser";

                MySqlCommand    cmd    = new MySqlCommand(statement, conn);
                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        RegularUser regularUser = new RegularUser();
                        regularUser.Id       = reader.GetInt32("Id");
                        regularUser.UserName = reader.GetString("UserName");
                        regularUser.Password = reader.GetString("Password");

                        regularUsersList.Add(regularUser);
                    }
                }
            }

            return(regularUsersList);
        }
예제 #9
0
    public Tuple <int, string> InsertFriend(ref RegularUser user, ref RegularUser friend)
    {
        int    id;
        string message;

        switch (userData.InsertFriend(user, friend))
        {
        case 0:
            id      = 1;
            message = "Amistad creada!";
            break;

        case 1:
            id      = 2;
            message = "Amistad ya existe";
            break;

        default:
            id      = 2;
            message = "Error al agregar una amistad. Contacte a un administrador";
            break;
        }

        Tuple <int, string> n = new Tuple <int, string>(id, message);

        return(n);
    }
예제 #10
0
        public ViewResult RemoveUser(int id)    //remove user by given id parameter sent from admin view. it also removes the picture
        {                                       //of that user. remove user by simply calling a function from user repository.
            List <RegularUser> userData = UserRepository.ReturnUsers();
            RegularUser        regUsr   = userData.Find(regUsr => regUsr.Id == id);

            if (!string.IsNullOrEmpty(regUsr.picAddress))
            {
                string[] listStr = regUsr.picAddress.Split("~/");               //split the path, as we only need path after ~/.
                var      path    = Path.Combine(Environment.CurrentDirectory, "wwwroot", listStr[listStr.Length - 1]);
                System.IO.File.Delete(path);
            }
            UserRepository.RemoveUser(id);
            List <Post> postData = PostRepository.ReturnPosts();

            foreach (Post p in postData)
            {
                if (p.Usr == regUsr.Username)
                {
                    PostRepository.RemovePost(p.Id);
                }
            }
            userData = UserRepository.ReturnUsers();
            List <RegularUser> newData = checkForAdmins(userData); //to check that there must be no admin should present in the list to show.

            return(View("AdminPanel", newData));
        }
예제 #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (rememberCheckBox.Checked)       // remember email for next time if user checked the box
                {
                    Properties.Settings.Default.Email = textBox1.Text;
                    Properties.Settings.Default.Save();
                }

                RegularUser currentUser = new RegularUser(textBox1.Text, textBox2.Text);
                Menu        menu        = new Menu(this, currentUser);

                LoginEventArgs logArgs = new LoginEventArgs(currentUser);
                OnRaiseLoginEvent(logArgs);

                this.Hide();
                menu.Closed += (s, args) => this.Close();
                menu.Show();
            }
            catch (Exception err)
            {
                label3.Visible = true;
            }
        }
        public IActionResult ViewPost(int id)   //selectes which view to return with the post having id given in parameter.
        {
            if (!HttpContext.Session.Keys.Contains("CurrentUser"))
            {
                return(RedirectToAction("Login", "Registration"));
            }
            List <RegularUser> userData = UserRepository.ReturnUsers();
            RegularUser        ru       = userData.Find(ru => ru.Username == HttpContext.Session.GetString("CurrentUser"));

            ViewBag.Id = ru.Id;
            List <Post> postData = PostRepository.ReturnPosts();
            Post        p        = postData.Find(p => p.Id == id);
            RegularUser usr      = userData.Find(usr => usr.Username == p.Usr);

            if (string.IsNullOrEmpty(usr.picAddress))
            {
                p.usrPP = "~/images/temp.jpg";
            }
            else
            {
                p.usrPP = usr.picAddress;
            }
            if (p.Usr == HttpContext.Session.GetString("CurrentUser"))  //if user clicks on its own post then this view will be showm.
            {
                return(View("ViewOwnPost", p));
            }
            else                      //if user clicks on someone else post then this post will be shown.
            {
                return(View("ViewOtherPost", p));
            }
        }
예제 #13
0
 public void Dispose()
 {
     RegularUser.Dispose();
     ManagerUser.Dispose();
     AdminUser.Dispose();
     Server.Dispose();
 }
예제 #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["REG_USER"] == null)
        {
            Response.Redirect("SignInRegular.aspx");
        }
        else if (Session["HIKE"] == null)
        {
            Response.Redirect("HikeLobby.aspx");
        }
        if (!IsPostBack)
        {
            if (dd_qualitylevel.Items.Count == 0)
            {
                FillDropDownLists();
            }

            RegularUser regularUser = (RegularUser)Session["REG_USER"];
            LoggedInUsername.Text = regularUser.Account;

            Hike hike = (Hike)Session["HIKE"];
            hike.Route = new Route();
            hike.Route.ListOfPoints = new List <Point>();
            Session["HIKE"]         = hike;
        }
        DisplayRoute();
    }
예제 #15
0
        public IRegularUser CreateUser(string name, string lastName, string username, string password, string confirmPassword)
        {
            RegularUser user = new RegularUser(name, lastName, username, password);

            var query = "SELECT username FROM librarycatalog.users WHERE username=@username";

            if (CheckIfUsernameExists(query, username) == false)
            {
                user.Name = username;
            }
            else
            {
                throw new ArgumentException("This user already exists.");
            }

            if (CheckPasswords(password, confirmPassword) == true)
            {
                user.Password = password;
            }
            else
            {
                throw new ArgumentException("Passwords do not match.");
            }

            return(user);
        }
예제 #16
0
        public RegularUser GetById(int id)
        {
            RegularUser regularUser = new RegularUser();

            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                string statement = "SELECT * FROM regularuser WHERE Id = @Id";

                MySqlCommand cmd = new MySqlCommand(statement, conn);

                cmd.Parameters.AddWithValue("@Id", id);
                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        regularUser.Id       = reader.GetInt32("Id");
                        regularUser.UserName = reader.GetString("UserName");
                        regularUser.Password = reader.GetString("Password");
                    }
                }
            }

            return(regularUser);
        }
        public async Task <IActionResult> Register([FromBody] UserRegistration model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("", "Passwords do not match!");
                return(BadRequest(ModelState));
            }

            var user = new RegularUser()
            {
                UserName = model.Username,
                Email    = model.Email,
                Name     = model.Name,
                Surname  = model.Surname,
                City     = model.City,
                Phone    = model.Phone
            };

            var result = await _userService.RegisterUser(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok(200));
        }
예제 #18
0
        public User ProcessLogin(string username, string password)
        {
            int    result;
            UserDB userDB      = new UserDB();
            string md5password = Encrypt.GetMD5(password);

            // result = userDB.CheckUser(username, md5password);
            result = 1;
            User userLogin = null;


            if (result == 1)
            {
                userLogin          = new AdminUser();
                userLogin.UserName = username;
                userLogin.Password = password;
            }
            else if (result == 2)
            {
                userLogin          = new RegularUser();
                userLogin.UserName = username;
                userLogin.Password = password;
            }

            return(userLogin);
        }
        public async Task <IActionResult> PostCarRate(long id, [FromBody] CarVehicleRatingDTO model)
        {
            if (ModelState.IsValid)
            {
                CarReservation vehicleReser = await _reservationService.GetCarReservationById(id);

                Vehicle vehicle = await _vehicleService.GetVehicleById(vehicleReser.VehicleId);

                RegularUser user = await _userService.GetCurrentUser();

                CarCompanyRating ccRate = new CarCompanyRating();
                ccRate.CarReservationId = id;
                ccRate.CarCompanyId     = vehicle.CarCompanyId;
                ccRate.UserId           = user.Id;
                ccRate.Rate             = model.ratingCarCompany;

                VehicleRating vehicleRate = new VehicleRating();
                vehicleRate.CarReservationId = id;
                vehicleRate.VehicleId        = vehicle.VehicleId;
                vehicleRate.Rate             = model.ratingVehicle;
                vehicleRate.UserId           = user.Id;

                await _userService.AddCarRating(ccRate);

                await _userService.AddVehicleRating(vehicleRate);

                return(Ok(200));
            }
            return(BadRequest());
        }
예제 #20
0
    public Tuple <int, string> removeLike(RegularUser user, Hike hike)
    {
        int    id;
        string message;

        switch (likeData.RemoveLike(user, hike))
        {
        case 0:
            id      = 1;
            message = "Has removido tu like de esta caminata!";
            break;

        case 1:
            id      = 2;
            message = "No se le puede remover un like a la caminata que no le has dado like.";
            break;

        default:
            id      = 2;
            message = "Error al agregar un like. Contacte a un administrador";
            break;
        }

        Tuple <int, string> n = new Tuple <int, string>(id, message);

        return(n);
    }
        public async Task <IActionResult> PostAvioRate(long id, [FromBody] AvioFlightRatingDTO model)
        {
            if (ModelState.IsValid)
            {
                FlightReservation flightReser = await _reservationService.GetFlightReservationById(id);

                Flight flight = await _flightService.GetFlight(flightReser.FlightId);

                RegularUser user = await _userService.GetCurrentUser();

                AvioCompanyRating acRate = new AvioCompanyRating();
                acRate.AvioCompanyId       = flight.AvioCompanyId;
                acRate.FlightReservationId = id;
                acRate.UserId = user.Id;
                acRate.Rate   = model.ratingAvioCompany;

                FlightRating flightRate = new FlightRating();
                flightRate.FlightId            = flight.FlightId;
                flightRate.FlightReservationId = id;
                flightRate.Rate   = model.ratingFlight;
                flightRate.UserId = user.Id;

                await _userService.AddAvioRating(acRate);

                await _userService.AddFlightRating(flightRate);

                return(Ok(200));
            }
            return(BadRequest());
        }
예제 #22
0
    public Tuple <int, string> addLike(RegularUser user, Hike hike)
    {
        int    id;
        string message;

        switch (likeData.InsertLike(user, hike))
        {
        case 0:
            id      = 1;
            message = "Le has dado like a la caminata!";
            break;

        case 1:
            id      = 2;
            message = "Ya le habias dado like a esta caminata!";
            break;

        default:
            id      = 2;
            message = "Error al agregar un like. Contacte a un administrador";
            break;
        }

        Tuple <int, string> n = new Tuple <int, string>(id, message);

        return(n);
    }
예제 #23
0
    public int RemoveFriend(RegularUser user, RegularUser friend)
    {
        int resultID;

        try
        {
            SqlConnection connection = ManageDatabaseConnection("Open", "regular");
            using (SqlCommand sqlCommand = new SqlCommand("removeFriend", connection))
            {
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.AddWithValue("@UserId", user.UserId);
                sqlCommand.Parameters.AddWithValue("@FriendId", friend.UserId);

                var returnParameter = sqlCommand.Parameters.Add("@ReturnVal", SqlDbType.Int);
                returnParameter.Direction = ParameterDirection.ReturnValue;

                sqlCommand.ExecuteNonQuery();
                resultID = Convert.ToInt32(returnParameter.Value);
            }
            ManageDatabaseConnection("Close", "regular");
        }
        catch (SqlException sqlException)
        {
            throw sqlException;
        }
        //Debug.WriteLine(resultID);
        return(resultID);
    }
예제 #24
0
    public bool CheckEmail(RegularUser regularUser)
    {
        int errorId = -1;

        try
        {
            SqlConnection connection = ManageDatabaseConnection("Open", "regular");
            using (SqlCommand sqlCommand = new SqlCommand("checkEmail", connection))
            {
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.AddWithValue("@email", regularUser.Email);

                var returnParameter = sqlCommand.Parameters.Add("@errorId", SqlDbType.Int);
                returnParameter.Direction = ParameterDirection.ReturnValue;

                sqlCommand.ExecuteNonQuery();
                errorId = Convert.ToInt32(returnParameter.Value);
            }
            ManageDatabaseConnection("Close", "regular");
        }
        catch (SqlException sqlException)
        {
            throw sqlException;
        }

        if (errorId == 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
예제 #25
0
    public string InsertUser(RegularUser regularUser)
    {
        string responseMessage = "-------------------------------------------------------------------";

        try
        {
            SqlConnection connection = ManageDatabaseConnection("Open", "regular");
            using (SqlCommand sqlCommand = new SqlCommand("addUser", connection))
            {
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.AddWithValue("@account", regularUser.Account);
                sqlCommand.Parameters.AddWithValue("@password", regularUser.Password);
                sqlCommand.Parameters.AddWithValue("@roleId", regularUser.RoleId);
                var returnParameter = sqlCommand.Parameters.AddWithValue("@responseMessage", responseMessage);

                //var returnParameter = sqlCommand.Parameters.Add("@responseMessage", SqlDbType.NVarChar, 250);
                returnParameter.Direction = ParameterDirection.InputOutput;
                sqlCommand.ExecuteNonQuery();
                responseMessage = Convert.IsDBNull(returnParameter.Value) ? null : returnParameter.Value.ToString();
            }
            ManageDatabaseConnection("Close", "regular");
        }
        catch (SqlException sqlException)
        {
            throw sqlException;
        }
        return(responseMessage);
    }
예제 #26
0
        public async Task <IActionResult> CreateCarAdmin([FromBody] RegisterAdminDTO adminDTO)
        {
            if (ModelState.IsValid)
            {
                if (await AvioAdminService.AdminExists(adminDTO.Username))
                {
                    return(BadRequest("Admin already exists with that username!"));
                }

                if (await CarAdminService.AdminExists(adminDTO.Username))
                {
                    return(BadRequest("Admin already exists with that username!"));
                }

                if (adminDTO.Password != adminDTO.ConfirmPassword)
                {
                    return(BadRequest("Password and confirmation password don't match!"));
                }

                RegularUser user = new RegularUser()
                {
                    UserName = adminDTO.Username,
                    Status   = UserStatus.Activated
                };

                var foundAdmin = await UserManager.FindByNameAsync(user.UserName) != null;

                if (!foundAdmin)
                {
                    var createdAdmin = await UserManager.CreateAsync(user, adminDTO.Password);

                    if (createdAdmin.Succeeded)
                    {
                        await UserManager.AddToRoleAsync(user, "CarAdmin");

                        CarAdmin admin = new CarAdmin()
                        {
                            UserId       = user.Id,
                            CarCompanyId = (await RentACarService.GetCompanyByName(adminDTO.CompanyName)).CarCompanyId
                        };

                        if (admin.CarCompanyId > 0)
                        {
                            await CarAdminService.RegisterAdmin(user.Id, admin);

                            return(Ok(200));
                        }
                        else
                        {
                            return(BadRequest("Car company not found!"));
                        }
                    }
                }

                return(BadRequest("Admin already exists!"));
            }

            return(BadRequest("No sufficient data provided."));
        }
        public void InstantiateRegularUser()
        {
            //Arrange
            var regularUser = new RegularUser();

            //Act & Assert
            Assert.IsInstanceOf <RegularUser>(regularUser);
        }
예제 #28
0
        public void RegularUserConstructor_ShouldInitializeFollowingCollectionCorrectly()
        {
            var user = new RegularUser();

            var starredUsers = user.Following;

            Assert.That(starredUsers, Is.Not.Null.And.InstanceOf <ICollection <RegularUser> >());
        }
예제 #29
0
        public void RegularUserConstructor_ShouldInitializeLikedImagesCollectionCorrectly()
        {
            var user = new RegularUser();

            var likedImaged = user.LikedImages;

            Assert.That(likedImaged, Is.Not.Null.And.InstanceOf <ICollection <UploadedImages.UploadedImage> >());
        }
예제 #30
0
        public void RegularUser_ShouldHaveParameterlessConstructor()
        {
            // Arrange & Act
            var user = new RegularUser();

            // Assert
            Assert.IsInstanceOf <RegularUser>(user);
        }
예제 #31
0
        public async Task<ActionResult> RegisterRegular(RegisterRegularViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = new RegularUser { UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName };
                var result = await this.UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await this.UserManager.AddToRoleAsync(user.Id, "Regular");

                    await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    return this.RedirectToAction("Index", "Home");
                }

                this.AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return this.View(model);
        }