コード例 #1
0
 /// <summary>
 /// Create a new ConnectionRequest with the given users.
 /// </summary>
 /// <param name="sender">The User who requesting a connection.</param>
 /// <param name="requestedUser">The user receiving the request.</param>
 public ConnectionRequest(User sender, User requestedUser)
 {
     this.Sender = sender;
     this.Sender_Id = sender.Id;
     this.RequestedUser = requestedUser;
     this.RequestedUser_Id = requestedUser.Id;
 }
コード例 #2
0
ファイル: Connection.cs プロジェクト: sennera/tents-n-trails
 /// <summary>
 /// Create a new Connection with the given users.
 /// </summary>
 /// <param name="user1">The first User.</param>
 /// <param name="user2">The second User.</param>
 public Connection(User user1, User user2)
 {
     this.User1 = user1;
     this.User1_Id = user1.Id;
     this.User2 = user2;
     this.User2_Id = user2.Id;
 }
コード例 #3
0
 /// <summary>
 /// Create a new FriendNotification for the targetUser about a potentialFriend.
 /// </summary>
 /// <param name="targetUser">The user who will see the notification.</param>
 /// <param name="potentialFriend">The user who the notification is about.</param>
 /// <param name="description">The string description of this notification.</param>
 public static FriendNotification MakeFriendNotification(User targetUser, User potentialFriend, string description)
 {
     return new FriendNotification()
     {
         Description = description,
         DateCreated = DateTime.UtcNow,
         DateRead = null,
         User = targetUser,
         UserID = targetUser.Id,
         PotentialFriend = potentialFriend,
         PotentialFriend_Id = potentialFriend.Id,
     };
 }
コード例 #4
0
        //upload a profile picture for a user of the given user.
        async public Task<string> UploadProfilePictureAsync(HttpPostedFileBase photoToUpload, User user)
        {
            // remove old image from blob storage
            if (user.ProfilePictureUrl.Contains(PhotoService.IMAGE_URL_BASE))
            {
                bool deleteResult = await DeletePhotoAsync(user.ProfilePictureUrl);
                System.Diagnostics.Debug.WriteLine(String.Format("Delete old image: '{0}' successful: {1}", user.ProfilePictureUrl, deleteResult));
            }
            else
            {
                System.Diagnostics.Debug.WriteLine(String.Format("Old image not deleted; matches '{0}'", Image.DEFAULT_PROFILE_PICTURE_URL));
            }

            string imageName = String.Format("profile-picture-{0}{1}{2}",
                user.UserName, 
                Guid.NewGuid().ToString(), 
                Path.GetExtension(photoToUpload.FileName));
            return await UploadPhotoAsync(photoToUpload, imageName);
        }
コード例 #5
0
 /// <summary>
 /// Convenience method for creating a Notification for a connection request.
 /// </summary>
 /// <param name="target">The user who will see the notification.</param>
 /// <param name="potential">The user who the notification is about.</param>
 /// <returns>A new FriendNotification for the target user which says "You have a new connection request from 'potential.UserName'</returns>
 public static FriendNotification CreateRequestNotification(User target, User potential)
 {
     return MakeFriendNotification(target, potential, REQUEST);
 }
コード例 #6
0
 /// <summary>
 /// Convenience method for creating a Notification about a denied connection request.
 /// </summary>
 /// <param name="target">The user who will see the notification.</param>
 /// <param name="potential">The user who the notification is about.</param>
 /// <returns>A new FriendNotification for the target user which says "'potential.UserName' has denied your connection request."</returns>
 public static FriendNotification CreateDenyNotification(User target, User potential)
 {
     return MakeFriendNotification(target, potential, DENY);
 }
コード例 #7
0
 /// <summary>
 /// Convenience method for creating a Notification about a confirmed connection request.
 /// </summary>
 /// <param name="target">The user who will see the notification.</param>
 /// <param name="potential">The user who the notification is about.</param>
 /// <returns>A new FriendNotification for the target user which says "'potential.UserName' has confirmed your connection request."</returns>
 public static FriendNotification CreateConfirmNotification(User target, User potential)
 {
     return MakeFriendNotification(target, potential, CONFIRM);
 }
コード例 #8
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new User { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
コード例 #9
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User { UserName = model.UserName, FirstName = model.FirstName, 
                    LastName = model.LastName, Email = model.Email, EnrollmentDate = DateTime.Now, Private = model.Private };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    User currentUser = UserManager.FindByEmail(user.Email);//attempt to fix issue below

                    List<UserRecreation> userrecList = new List<UserRecreation>();

                    foreach (var userRec in model.RecOptions)
                    {
                        if (userRec.IsChecked)
                        {
                            UserRecreation ur = userRec;
                            ur.User = currentUser.Id;//fixed the issue. Now just go change the profile page to grab the relevent information about userRecs
                            db.UserRecreations.Add(ur);
                        }
                    }

                    db.SaveChanges();
                    // 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 RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #10
0
 private async Task SignInAsync(User user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(UserManager));
 }