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); }
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); }
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); }
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(); }
public void DeleteUser(BursifyUser user) { using (IUnitOfWork uow = unitOfWorkFactory.CreateUnitOfWork()) { userRepository.Delete(user); uow.Commit(); } }
public void UpdateUser(BursifyUser user) { using (IUnitOfWork uow = _unitOfWorkFactory.CreateUnitOfWork()) { _userRepository.Save(user); uow.Commit(); } }
public bool IsEndorsed(BursifyUser user, int campaignId) { var campaign = user.Upvotes.FirstOrDefault(x => x.ID == campaignId); if (campaign == null) { return(false); } return(true); }
public BursifyUser GetUserById(int id) { BursifyUser user = null; using (IUnitOfWork uow = _unitOfWorkFactory.CreateUnitOfWork()) { user = _userRepository.GetUserById(id); } return(user); }
public BursifyUser GetUserByEmail(string email) { BursifyUser user = null; using (IUnitOfWork uow = _unitOfWorkFactory.CreateUnitOfWork()) { user = _userRepository.GetUserByEmail(email); } return(user); }
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); }
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(); } }
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); }
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); }
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) }); }
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(); }
public bool IsPasswordValid(BursifyUser user, string password) { return(_cryptoService.HashPassword(password, user.PasswordSalt) == user.PasswordHash); }