/// <summary> /// Creates a profile during user creation phase /// </summary> /// <param name="email"></param> private void CreateProfile(string email) { //Create and Access Permission AccessPermission ap = new AccessPermission() { PublicAccess = true, FriendAccess = true, PublisherAccess = true, MinorAccess = true }; db.AccessPermissions.Add(ap); db.SaveChanges(); //Create new LPProfile object LPProfile lpProfile = new LPProfile(); //Get LPUser LPUser lpUser = db.LPUsers.Where(em => em.Email == email).SingleOrDefault(); //Set Profile UserID lpProfile.UserID = lpUser.UserID; //Add AcessPermission obj lpProfile.AccessPermission = ap; //Add to db db.LPProfiles.Add(lpProfile); db.SaveChanges(); //Proceed to next phase CreateProfileRole(lpUser.UserID); }
public ActionResult Index() { //Check if logged in ==> Should be caught by [Authorize] but just in case if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser((string)currentUser.Email); try { //ViewBag.TwitterName = UnitOfWork.Twitter.GetTwitterEndTime(id); ViewBag.TwitterName = repository.GetTwitterTag(lpCurrentUser.UserID); DateTime EndTime = repository.GetTwitterEndTime(lpCurrentUser.UserID); ViewBag.EndTime = EndTime; //return View(db.Writings.ToList()); return(View(wrepo.GetAll())); } catch { // return View(db.Writings.ToList()); return(View(wrepo.GetAll())); } //} }
public ActionResult TwitterLogOut() { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser(currentUser.Email); try { repository.Remove(lpCurrentUser.UserID); repository.Save(); } catch (Exception e) { //do nothing Debug.WriteLine(e.Message); } return(RedirectToAction("Settings/" + lpCurrentUser.UserID)); }
public ActionResult Settings() { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser((string)currentUser.Email); try { ViewBag.TwitterName = repository.GetTwitterTag(lpCurrentUser.UserID); DateTime EndTime = repository.GetTwitterEndTime(lpCurrentUser.UserID); ViewBag.EndTime = EndTime; return(View()); } catch { return(View()); } // return View(); //} }
public async Task <LPUserViewModel> Handle(CreateUserCommand request, CancellationToken cancellationToken) { LPUserViewModel user = await _mediator.Send(new GetLPUserQuery() { FacebookId = request.FacebookId }); if (user == null) { LPUser entity = new LPUser() { FacebookId = request.FacebookId, CreatedAt = request.CreatedAt, Deleted = request.Deleted, Email = request.Email, FirstName = request.FirstName, LastName = request.LastName, Phone = request.Phone, ProfilePicture = request.ProfilePicture, MessengerId = request.MessengerId }; _context.LPUsers.Add(entity); await _context.SaveChangesAsync(cancellationToken); return(_mapper.Map <LPUserViewModel>(entity)); } else { return(user); } }
public ActionResult DeleteConfirmed(int id) { LPUser lPUser = db.LPUsers.Find(id); db.LPUsers.Remove(lPUser); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult TwitterCallback(string oauth_token, string oauth_verifier) { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser((string)currentUser.Email); var requestToken = new OAuthRequestToken { Token = oauth_token }; string Key = System.Configuration.ConfigurationManager.AppSettings["twKey"]; string Secret = System.Configuration.ConfigurationManager.AppSettings["twSecret"]; Twitter twitterUser = new Twitter { }; try { TwitterService service = new TwitterService(Key, Secret); OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier); service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret); VerifyCredentialsOptions option = new VerifyCredentialsOptions(); TwitterUser user = service.VerifyCredentials(option); TempData["Token"] = oauth_token; TempData["VToken"] = oauth_verifier; TempData["UserTag"] = user.ScreenName; TempData["Name"] = user.Name; TempData["Userpic"] = user.ProfileImageUrl; int TwID = lpCurrentUser.UserID; var Token = oauth_token; var VToken = oauth_verifier; String TwName = user.ScreenName; String TagName = user.Name; twitterUser.UserID = lpCurrentUser.UserID; twitterUser.TwName = TwName; twitterUser.TwTag = TagName; twitterUser.TwOauth = Token; twitterUser.TwVOauth = VToken; twitterUser.Date = DateTime.Now; twitterUser.EndDate = DateTime.Now.AddMinutes(60); repository.Add(twitterUser); repository.Save(); return(RedirectToAction("Settings/" + lpCurrentUser.UserID)); } catch { throw new System.InvalidOperationException("Twitter didnt like it"); } }
public async Task <ActionResult> Register(RegisterViewModel model) { RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper(); if (string.IsNullOrEmpty(recaptchaHelper.Response)) { ModelState.AddModelError("reCAPTCHA", "Please complete the reCAPTCHA"); return(View(model)); } else { RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse(); if (recaptchaResult != RecaptchaVerificationResult.Success) { ModelState.AddModelError("reCAPTCHA", "The reCAPTCHA is incorrect"); return(View(model)); } } if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Username, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); var lpUser = new LPUser(); lpUser.Email = model.Email; lpUser.Username = model.Username; //Used for testing //string[] splitstring = model.Email.Split('@'); //lpUser.Username = splitstring[0]; if (result.Succeeded) { db.LPUsers.Add(lpUser); db.SaveChanges(); CreateProfile(model.Email); System.Diagnostics.Debug.WriteLine("Registered"); // Comment the following line to prevent log in until the user is confirmed. await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account"); ViewBag.Message = "Check your email and confirm your account, you must be confirmed " + "before you can log in."; //Call the ActionResult method that creates an LPUser //return RedirectToAction("LPUserCreate", "Home", new { Email = model.Email }); return(View("Info")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Edit([Bind(Include = "UserID,Email,Birthdate,GivenName,Surname,PhoneNumber,Username")] LPUser lPUser) { if (ModelState.IsValid) { db.Entry(lPUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lPUser)); }
private async Task <AuthorizationTokensResource> CreateAccessTokens(LPUser user, string deviceId, string deviceName) { var accessToken = _jwtHandler.CreateAccessToken(new Guid(user.Id)); var refreshToken = _jwtHandler.CreateRefreshToken(new Guid(user.Id)); return(new AuthorizationTokensResource { AccessToken = accessToken, RefreshToken = refreshToken }); }
public ActionResult Create([Bind(Include = "UserID,Email,Birthdate,GivenName,Surname,PhoneNumber,Username")] LPUser lPUser) { if (ModelState.IsValid) { db.LPUsers.Add(lPUser); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lPUser)); }
public ActionResult Create([Bind(Include = "Email, Birthdate, FirstName, LastName, PhoneNumber, Username")] LPUser usr) { if (ModelState.IsValid) { db.LPUsers.Add(usr); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Index")); }
public ActionResult TwitterAuth() { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser(currentUser.Email); try { repository.Remove(lpCurrentUser.UserID); repository.Save(); } catch (Exception e) { //do nothing Debug.WriteLine(e.Message); } String sid = lpCurrentUser.UserID.ToString(); string Key = System.Configuration.ConfigurationManager.AppSettings["twKey"]; string Secret = System.Configuration.ConfigurationManager.AppSettings["twSecret"]; TwitterService service = new TwitterService(Key, Secret); OAuthRequestToken requestToken = service.GetRequestToken("https://landingpad.azurewebsites.net/Home/TwitterCallback" + "?id=" + sid); //For deployment //OAuthRequestToken requestToken = service.GetRequestToken("https://localhost:44315/Home/TwitterCallback" + "?id=" + sid); //For testing purposes Uri uri = service.GetAuthenticationUrl(requestToken); if (CheckToken(Key)) { if (CheckToken(Secret)) { return(Redirect(uri.ToString())); } else { ViewBag.FileStatus = "Invalid Twitter Key"; return(View()); } } else { ViewBag.FileStatus = "Model Invalid"; return(View()); } }
public ActionResult Delete(int?id) { if (id == null) { return(HttpNotFound()); } LPUser usr = db.LPUsers.Find(id); if (usr == null) { return(HttpNotFound()); } return(View(usr)); }
// GET: LPUsers/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LPUser lPUser = db.LPUsers.Find(id); if (lPUser == null) { return(HttpNotFound()); } return(View(lPUser)); }
// GET: LPProfiles public ActionResult Index() { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser(currentUser.Email); return(View(lprepo.GetAll())); }
public async Task <LPUserViewModel> Handle(GetLPUserQuery request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.Id)) { List <LPUser> users = await _context.LPUsers.ToListAsync(); return(_mapper.Map <LPUserViewModel>(users.FirstOrDefault(x => x.FacebookId == request.FacebookId))); } else { LPUser user = await _context.LPUsers.FindAsync(request.Id); return(_mapper.Map <LPUserViewModel>(user)); } }
public ActionResult LPUserCreate(string Email) { //Create the User var lpUser = new LPUser(); lpUser.Email = Email; //Used for testgin get Username string[] splitstring = Email.Split('@'); lpUser.Username = splitstring[0]; //Add to DB db.LPUsers.Add(lpUser); db.SaveChanges(); //View Message from Register ViewBag.Message = "Check your email and confirm your account, you must be confirmed " + "before you can log in."; //Return the Info View return(View("Info")); }
public async Task <LPUser> GetUserFromFacebookAsync(string facebookToken) { var result = await GetAsync <dynamic>(facebookToken, "me", "fields=first_name,last_name,email,picture.width(100).height(100)"); if (result == null) { throw new Exception("User from this token not exist"); } var account = new LPUser() { Email = result.email, FirstName = result.first_name, LastName = result.last_name, ProfilePicture = result.picture.data.url }; return(account); }
// GET: LPProfiles/Details/5 public ActionResult Details() { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser(currentUser.Email); //Get the current user's profile based on the user ID LPProfile lPProfile = lprepo.Get(lpCurrentUser.UserID); if (lPProfile == null) { return(HttpNotFound()); } return(View(lPProfile)); }
// GET: LPProfiles/Edit/5 public ActionResult Edit() { if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser(currentUser.Email); LPProfile lPProfile = lprepo.Get(lpCurrentUser.UserID); if (lpCurrentUser == null) { return(HttpNotFound()); } ViewBag.UserID = new SelectList(db.LPUsers, "UserID", "Email", lpCurrentUser.UserID); return(View(lPProfile)); }
/// <summary> /// Allows a user to download a file out of the database /// </summary> /// <param name="id"></param> /// <returns> The file in the original format it was uploaded as</returns> public ActionResult Download(int?id) { //Check if logged in ==> Should be caught by [Authorize] but just in case if (!CheckLogin()) { return(RedirectToAction("Login", "Account")); } //Get the user's ID string uid = GetUserID(); //Get ASP.NET User Object ApplicationUser currentUser = GetUser(uid); //Get the LPUser based on ASP.NET User's e-mail LPUser lpCurrentUser = GetLPUser((string)currentUser.Email); //Get the LPProfile LPProfile lpProfile = GetLPProfile(lpCurrentUser.UserID); Writing wr = db.Writings.Find(id); if (wr == null) { return(HttpNotFound()); } //If the ProfileIDs don't match redirect to an error page if (wr.ProfileID != lpProfile.ProfileID) { return(RedirectToAction("DownloadError", "Error")); } UTF8Encoding encoding = new UTF8Encoding(); byte[] contentAsBytes = wr.Document; if (wr.DocType == "HTML" || wr.DocType == ".HTML") { this.HttpContext.Response.ContentType = "application/force-download"; this.HttpContext.Response.AddHeader("Content-Disposition", "filename=" + wr.WritingFileName); } else if (wr.DocType == "DOC" || wr.DocType == ".DOC") { this.HttpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + wr.WritingFileName); } else if (wr.DocType == "ODT" || wr.DocType == ".ODT") { this.HttpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + wr.WritingFileName); } else if (wr.DocType == "PDF" || wr.DocType == ".PDF") { this.HttpContext.Response.ContentType = "application/pdf"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + wr.WritingFileName); } else { this.HttpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + wr.WritingFileName); } this.HttpContext.Response.Buffer = true; this.HttpContext.Response.Clear(); this.HttpContext.Response.OutputStream.Write(contentAsBytes, 0, contentAsBytes.Length); this.HttpContext.Response.OutputStream.Flush(); this.HttpContext.Response.End(); return(View()); }
public static LPStoreOperator Create(LPUser value, LPUser pointer) => new LPStoreOperator { Value = value, Pointer = pointer };
public static LPStoreOperator Create(LPUser value) => new LPStoreOperator { Type = value.Type, Value = value };