Ejemplo n.º 1
0
        public async Task <IHttpActionResult> GetUser([FromUri] int id, [FromUri] string password,
                                                      [FromUri] string userEmail)
        {
            Eventual.Model.User u = ValidateUser(userEmail, password);

            if (u == null)
            {
                return(Unauthorized());
            }

            Eventual.DAL.User user = await db.Users.FindAsync(id);

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

            if (user.UserID != u.UserID)
            {
                return(Unauthorized());
            }

            db.Entry(user).State = System.Data.Entity.EntityState.Detached;
            return(Ok(user));
        }
Ejemplo n.º 2
0
 public void TestUser()
 {
     Eventual.Model.User user2 = CreateUser();
     Assert.AreEqual(user2.UserID, 500000017);
     Assert.AreEqual(user2.UserEmail, "*****@*****.**");
     Assert.AreEqual(user2.UserFirstName, "userfirst");
     Assert.AreEqual(user2.UserLastName, "userlast");
     Assert.AreEqual(user2.UserRoleID, 1);
 }
Ejemplo n.º 3
0
 public Eventual.Model.User CreateUser()
 {
     Eventual.Model.User user1 = new Eventual.Model.User();
     user1.UserID          = 500000017;
     user1.UserEmail       = "*****@*****.**";
     user1.UserFirstName   = "userfirst";
     user1.UserLastName    = "userlast";
     user1.UserPhoneNumber = "1234567891";
     user1.UserRoleID      = 1;
     return(user1);
 }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> PutUser([FromUri] int id, [FromBody] Eventual.Model.User user,
                                                      [FromUri] string userEmail, [FromUri] string password)
        {
            Eventual.Model.User updatedUser = null;

            Eventual.Model.User u = ValidateUser(userEmail, password);

            if (u == null)
            {
                return(Unauthorized());
            }

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

            try
            {
                if (user != null && user.UserHashedPassword != null)
                {
                    user.UserHashedPassword = ComputeHash(user.UserHashedPassword, new SHA256CryptoServiceProvider(),
                                                          Encoding.ASCII.GetBytes(GetDBSALT()));
                }

                //todo --- update the currently logged in user
                db.spUpdateUser(user.UserFirstName, user.UserLastName, user.UserEmail, user.UserBirthDate,
                                user.UserPhoneNumber, user.UserHashedPassword, user.UserImageURL, id).FirstOrDefault();

                updatedUser =
                    ConvertModels.ConvertEntityToModel.UserEntityToUserModel(db.Users.FirstOrDefault(newUser => newUser.UserEmail == userEmail));

                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (SqlException sqlEx)
            {
                return(BadRequest(sqlEx.Message));
            }

            updatedUser.UserHashedPassword = password;
            return(Ok(updatedUser));
        }
        //converts User to User Model
        public static Eventual.Model.User UserEntityToUserModel(Eventual.DAL.spUpdateUser_Result user)
        {
            Eventual.Model.User result = new Eventual.Model.User
            {
                UserBirthDate      = user.UserBirthDate,
                UserEmail          = user.UserEmail,
                UserFirstName      = user.UserFirstName,
                UserHashedPassword = user.UserHashedPassword,
                UserImageURL       = user.UserImageURL,
                UserLastName       = user.UserLastName,
                UserPhoneNumber    = user.UserPhoneNumber
            };

            return(result);
        }
        //converts User to User Model
        public static Eventual.Model.User UserEntityToUserModel(Eventual.DAL.User user)
        {
            Eventual.Model.User result = new Eventual.Model.User
            {
                UserBirthDate      = user.UserBirthDate,
                UserEmail          = user.UserEmail,
                UserEndDate        = user.UserEndDate,
                UserFirstName      = user.UserFirstName,
                UserStartDate      = user.UserStartDate,
                UserHashedPassword = user.UserHashedPassword,
                UserID             = user.UserID,
                UserImageURL       = user.UserImageURL,
                UserLastName       = user.UserLastName,
                UserPhoneNumber    = user.UserPhoneNumber,
                UserRole           = UserRoleEntityToUserRoleModel(user.UserRole),
                UserRoleID         = user.UserRoleID
            };

            return(result);
        }
Ejemplo n.º 7
0
        public async Task <IHttpActionResult> GetUsersEvents([FromUri] int id, [FromUri] string userEmail,
                                                             [FromUri] string password)
        {
            Eventual.DAL.User user = await db.Users.FindAsync(id);

            Eventual.Model.User u = ValidateUser(userEmail, password);

            if (u == null)
            {
                return(Unauthorized());
            }

            //return a bad request response
            if (user == null)
            {
                return(BadRequest(ModelState));
            }

            //returns an ok with status code
            return(Ok(GetAllUsersEvents(id)));
        }
Ejemplo n.º 8
0
        public HttpResponseMessage RegisterEvent([FromUri] int userID, [FromUri] int eventID,
                                                 [FromUri] string userEmail, [FromUri] string password)
        {
            Eventual.Model.User u = ValidateUser(userEmail, password);

            if (u == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            if (CurrentEventExists(userID, eventID) || PastEventExists(userID, eventID))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Already added event"));
            }

            try
            {
                if (!UserExists(userID) || !EventExists(eventID))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid request"));
                }
            }
            catch (SqlException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (EntityException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }

            db.spJoinRegisteredEventUserId(userID, eventID);

            return(Request.CreateResponse(HttpStatusCode.OK, GetAllUsersEvents(userID)));
        }
Ejemplo n.º 9
0
        public async Task <IHttpActionResult> SignUpUser([FromBody] Eventual.Model.User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (db.Users.Count(u => u.UserEmail == user.UserEmail) > 0)
            {
                return(BadRequest("Please login."));
            }

            user.UserHashedPassword = ComputeHash(user.UserHashedPassword, new SHA256CryptoServiceProvider(),
                                                  Encoding.ASCII.GetBytes(GetDBSALT()));
            Eventual.DAL.User DALUser = ConvertModels.ConvertModelToEntity.UserModelToUserEntity(user);
            db.spCreateUser(DALUser.UserEmail, DALUser.UserHashedPassword);
            await db.SaveChangesAsync();

            Eventual.Model.User newUser =
                ConvertModels.ConvertEntityToModel.UserEntityToUserModel(db.Users.FirstOrDefault(u => u.UserEmail == user.UserEmail));
            return(Ok(newUser));
        }
        //converts User to User Model
        public static Eventual.DAL.User UserModelToUserEntity(Eventual.Model.User user)
        {
            Eventual.DAL.User result = new Eventual.DAL.User
            {
                UserID             = user.UserID,
                UserBirthDate      = user.UserBirthDate,
                UserStartDate      = user.UserStartDate,
                UserEmail          = user.UserEmail,
                UserEndDate        = user.UserEndDate,
                UserFirstName      = user.UserFirstName,
                UserLastName       = user.UserLastName,
                UserHashedPassword = user.UserHashedPassword,
                UserImageURL       = user.UserImageURL,
                UserPhoneNumber    = user.UserPhoneNumber,
                UserRoleID         = user.UserRoleID,
                UserRole           = UserRoleModelToUserRoleEntity(user.UserRole),
                EventRegistrations = EventRegistrationsModelToEventRegistrationsEntity(user.EventRegistrations),
                SavedEvents        = SavedEventsModelToSavedEventsEntity(user.SavedEvents)
            };

            return(result);
        }
Ejemplo n.º 11
0
        public HttpResponseMessage DropRegisteredEvent([FromUri] int userID, [FromUri] int registeredEvent,
                                                       [FromUri] string userEmail, [FromUri] string password)
        {
            var temp = db.Users.ToList();

            Eventual.Model.User u = ValidateUser(userEmail, password);

            if (u == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            if (!UserExists(userID) || (!CurrentEventExists(userID, registeredEvent) &&
                                        !PastEventExists(userID, registeredEvent)))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.spDropRegisteredEventWithUserId(userID, registeredEvent);

            return(Request.CreateResponse(HttpStatusCode.OK,
                                          db.spGetAllCurrentRegisteredEventsForSpecificUser(userID)));
        }