예제 #1
0
        public HttpResponseMessage GetUser(HttpRequestMessage request, int userId)
        {
            BursifyUser user;
            BursifyUser userVm = null;

            if (_userApi.GetUserType(userId).Equals("Student"))
            {
                var student = _studentApi.GetStudent(userId);
                student.NumberOfViews += 1;
                _studentApi.SaveStudent(student);

                user   = _userApi.GetCompletStudentUser(userId);
                userVm = new BursifyUserViewModel().MapStudentUser(user);
            }
            else
            {
                user   = _userApi.GetCompletSponsorUser(userId);
                userVm = new BursifyUserViewModel().MapSponsorUser(user);
            }

            userVm.PasswordHash = null;
            userVm.PasswordSalt = null;

            var response = request.CreateResponse(HttpStatusCode.OK, userVm);

            return(response);
        }
예제 #2
0
        public BursifyUser RegisterUser(string userEmail, string password, string userType)
        {
            BursifyUser user = null;

            using (IUnitOfWork uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                var existingUser = _userRepository.GetUserByEmail(userEmail);
                if (existingUser != null)
                {
                    return(null);
                }

                var salt = _cryptoService.CreateSalt();



                user = new BursifyUser
                {
                    Email              = userEmail,
                    PasswordHash       = _cryptoService.HashPassword(password, salt),
                    PasswordSalt       = salt,
                    UserType           = userType,
                    AccountStatus      = "Active",
                    RegistrationDate   = DateTime.UtcNow,
                    ProfilePicturePath = "def"
                };

                _userRepository.Save(user);
                uow.Commit();
            }
            return(user);
        }
예제 #3
0
        public HttpResponseMessage GetUser(HttpRequestMessage request, string email)
        {
            BursifyUser user;
            BursifyUser userVm = null;
            Guid        guid   = new Guid();

            //guid = Guid.NewGuid();


            if (_userApi.GetUserType(email).Equals("Student", StringComparison.OrdinalIgnoreCase))
            {
                user   = _userApi.GetCompletStudentUser(email);
                userVm = new BursifyUserViewModel().MapStudentUser(user);
            }
            else
            {
                user   = _userApi.GetCompletSponsorUser(email);
                userVm = new BursifyUserViewModel().MapSponsorUser(user);
            }

            userVm.PasswordHash = null;
            userVm.PasswordSalt = null;

            var response = request.CreateResponse(HttpStatusCode.OK, userVm);

            return(response);
        }
예제 #4
0
        public void DataInsert()
        {
            var dataSession = new DataSession();
            var uowFactory  = new UnitOfWorkFactory(dataSession);
            var uow         = uowFactory.CreateUnitOfWork();

            var user = new BursifyUser()
            {
            };

            user.Email              = "*****@*****.**";
            user.PasswordHash       = "password123";
            user.PasswordSalt       = "passwordSalt";
            user.AccountStatus      = "Active";
            user.UserType           = "Student";
            user.RegistrationDate   = DateTime.Today;
            user.Biography          = "Bio stuff";
            user.CellphoneNumber    = "0840924299";
            user.TelephoneNumber    = "0123456789";
            user.ProfilePicturePath = "somewhereSafe";

            var report = new StudentReport()
            {
                StudentId         = 1,
                Average           = 75,
                ReportInstitution = "UJ Test",
                ReportPeriod      = "Semester 1",
                ReportLevel       = "Second Year",
                Subjects          = new List <Subject>()
                {
                    new Subject()
                    {
                        Name         = "Informatics",
                        MarkAcquired = 75
                    },

                    new Subject()
                    {
                        Name         = "Maths",
                        MarkAcquired = 75
                    },

                    new Subject()
                    {
                        Name         = "Linear",
                        MarkAcquired = 75
                    }
                }
            };


            //uow.Context.Set<BursifyUser>().Add(user);
            uow.Context.Set <StudentReport>().Add(report);

            //uow.Context.Set<Subject>().Add(subject);

            uow.Context.SaveChanges();
            uow.Commit();
        }
예제 #5
0
 public void DeleteUser(BursifyUser user)
 {
     using (IUnitOfWork uow = unitOfWorkFactory.CreateUnitOfWork())
     {
         userRepository.Delete(user);
         uow.Commit();
     }
 }
예제 #6
0
 public void UpdateUser(BursifyUser user)
 {
     using (IUnitOfWork uow = _unitOfWorkFactory.CreateUnitOfWork())
     {
         _userRepository.Save(user);
         uow.Commit();
     }
 }
예제 #7
0
        public bool IsEndorsed(BursifyUser user, int campaignId)
        {
            var campaign = user.Upvotes.FirstOrDefault(x => x.ID == campaignId);

            if (campaign == null)
            {
                return(false);
            }
            return(true);
        }
예제 #8
0
        public BursifyUser GetUserById(int id)
        {
            BursifyUser user = null;

            using (IUnitOfWork uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                user = _userRepository.GetUserById(id);
            }

            return(user);
        }
예제 #9
0
        public BursifyUser GetUserByEmail(string email)
        {
            BursifyUser user = null;

            using (IUnitOfWork uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                user = _userRepository.GetUserByEmail(email);
            }

            return(user);
        }
예제 #10
0
        public Campaign EndorseCampaign(BursifyUser user, int campaignId)
        {
            var campaign = user.Upvotes.FirstOrDefault(x => x.ID == campaignId);

            if (campaign == null)
            {
                campaign = LoadById(campaignId);
                user.Upvotes.Add(campaign);
            }

            return(campaign);
        }
예제 #11
0
        public void UpdateUserPassword(BursifyUser user, string password)
        {
            using (IUnitOfWork uow = _unitOfWorkFactory.CreateUnitOfWork())
            {
                var salt = _cryptoService.CreateSalt();

                user.PasswordHash = _cryptoService.HashPassword(password, salt);
                user.PasswordSalt = salt;

                _userRepository.Save(user);
                uow.Commit();
            }
        }
예제 #12
0
        public BursifyUserViewModel ReverseMapUser(BursifyUser user)
        {
            ID                 = user.ID;
            Email              = user.Email;
            PasswordHash       = user.PasswordHash;
            PasswordSalt       = user.PasswordSalt;
            AccountStatus      = user.AccountStatus;
            UserType           = user.UserType;
            RegistrationDate   = user.RegistrationDate;
            Biography          = user.Biography;
            CellphoneNumber    = user.CellphoneNumber;
            TelephoneNumber    = user.TelephoneNumber;
            ProfilePicturePath = user.ProfilePicturePath;

            return(this);
        }
예제 #13
0
        public HttpResponseMessage Register(HttpRequestMessage request, RegistrationViewModel newUser)
        {
            HttpResponseMessage response = null;

            if (!ModelState.IsValid)
            {
                response = request.CreateResponse(HttpStatusCode.BadRequest, new { success = false });
            }
            else
            {
                BursifyUser user = _membershipApi.RegisterUser(newUser.UserEmail, newUser.Password, newUser.UserType);

                if (user != null)
                {
                    response = request.CreateResponse(HttpStatusCode.OK, new { success = true, user });

                    try
                    {
                        SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                        client.EnableSsl             = true;
                        client.Timeout               = 10000;
                        client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        client.UseDefaultCredentials = false;
                        client.Credentials           = new NetworkCredential("*****@*****.**", "Bursify123!");
                        MailMessage msg = new MailMessage();
                        msg.To.Add(user.Email);
                        msg.From    = new MailAddress("*****@*****.**");
                        msg.Subject = "Bursify Welcome!";
                        msg.Body    = string.Format("Welcome to Bursify,  {0}{0} Thank you for creating an account on our system. {0} Regards,{0} Bursify Team", Environment.NewLine);

                        client.Send(msg);
                    }
                    catch (Exception ex)
                    {
                        string str = ex.Message;
                    }
                }
                else
                {
                    response = request.CreateResponse(HttpStatusCode.OK, new { success = false });
                }
            }

            return(response);
        }
예제 #14
0
 public BursifyUser MapSponsorUser(BursifyUser user)
 {
     return(new BursifyUser()
     {
         ID = user.ID,
         Email = user.Email,
         PasswordHash = user.PasswordHash,
         PasswordSalt = user.PasswordSalt,
         AccountStatus = user.AccountStatus,
         UserType = user.UserType,
         RegistrationDate = user.RegistrationDate,
         Biography = user.Biography,
         CellphoneNumber = user.CellphoneNumber,
         TelephoneNumber = user.TelephoneNumber,
         ProfilePicturePath = user.ProfilePicturePath,
         Addresses = UserAddressViewModel.ReverseMapMultipleAddresses(UserAddressViewModel.MapMultipleAddresses((List <UserAddress>)user.Addresses)),
         Sponsor = (new SponsorViewModel()).ReverseMap(user.Sponsor)
     });
 }
예제 #15
0
        public void DataInsert()
        {
            var dataSession = new DataSession();
            var uowFactory  = new UnitOfWorkFactory(dataSession);
            var uow         = uowFactory.CreateUnitOfWork();

            var testUser = new BursifyUser()
            {
                //ID = 51,
                Email              = "*****@*****.**",
                PasswordHash       = "password123",
                PasswordSalt       = "passwordSalt",
                AccountStatus      = "Active",
                UserType           = "Student",
                RegistrationDate   = DateTime.Today,
                Biography          = "Bio stuff",
                CellphoneNumber    = "0840924299",
                TelephoneNumber    = "0123456789",
                ProfilePicturePath = "somewhereSafe"
            };

            var school = new Institution()
            {
                //ID = 25,
                Name    = "University of Johannesburg",
                Type    = "Tertiary",
                Website = "www.uj.ac.za",
            };



            var Students = //new List<Student>()
                           //{
                           new Student()
            {
                ID            = testUser.ID,
                InstitutionID = school.ID,
                AgreeTandC    = true,
                AverageMark   = 75,
                Age           = 20,
                Firstname     = "Brandon",
                Gender        = "Male",
            };

            //};

            school.Students.Add(Students); //= Students;

            var StudentReports =           //new List<StudentReport>()
                                           //{
                                 new StudentReport()
            {
                StudentId         = Students.ID,
                Average           = 75,
                ReportInstitution = "UJ",
                ReportLevel       = "Tertiary",
                ReportPeriod      = "Semester 1",

                //}
            };

            var Subjects = new List <Subject>()
            {
                new Subject()
                {
                    //ID = 12,
                    RequirementId = StudentReports.ID,
                    Name          = "CSC 1A10",
                    MarkAcquired  = 12
                },

                new Subject()
                {
                    //ID = 12,
                    RequirementId = StudentReports.ID,
                    Name          = "CSC 2A10",
                    MarkAcquired  = 21
                }
            };

            StudentReports.Subjects = Subjects;
            Students.StudentReports.Add(StudentReports);
            school.Students.Add(Students);
            //testUser.Student = Students;

            uow.Context.Set <BursifyUser>().Add(testUser);
            uow.Context.Set <Institution>().Add(school);
//            uow.Context.Set<Student>().Add(Students);
//            uow.Context.Set<StudentReport>().Add(StudentReports);
//            uow.Context.Set<Subject>().Add(Subjects[1]);

            uow.Context.SaveChanges();
            uow.Commit();
        }
예제 #16
0
 public bool IsPasswordValid(BursifyUser user, string password)
 {
     return(_cryptoService.HashPassword(password, user.PasswordSalt) == user.PasswordHash);
 }