public async Task <IActionResult> PostRegistration([FromBody] UserInfoContract info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user = new ApplicationUser
            {
                UserName    = info.UserName,
                Email       = info.Email,
                DateOfBirth = info.DateOfBirth,
                FirstName   = info.FirstName,
                LastName    = info.LastName,
                PhoneNumber = info.PhoneNumber.RemoveNonNumeric(),
                Gender      = info.Gender,
                AccountType = AccountType.Regular
            };
            //TODO: remove duplication between this and
            //      AccountController::Register(...)
            var result = await _userManager.CreateAsync(user, info.Password);

            if (result.Succeeded)
            {
                _logger.LogInformation("User created a new account with password from RegistrationController.");

                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                await _emailSender.SendEmailConfirmationAsync(user.Email, callbackUrl);

                return(Ok(true));
            }
            return(Ok(false));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetCurrentUserInfo()
        {
            var target = _httpContextAccessor.CurrentUserId();
            var user   = await _context.ApplicationUsers
                         .SingleOrDefaultAsync(s => s.Id.Equals(target));

            if (user == null)
            {
                return(NotFound());
            }
            var contract = new UserInfoContract()
            {
                Id          = user.Id,
                UserName    = user.UserName,
                FirstName   = user.FirstName,
                LastName    = user.LastName,
                DateOfBirth = user.DateOfBirth,
                Gender      = user.Gender,
                AccountType = user.AccountType,
                PhoneNumber = user.PhoneNumber,
                Email       = user.Email
            };

            return(Ok(contract));
        }
Exemplo n.º 3
0
 public UserInfoBriefViewCellModel(
     UserInfoContract userInfoContract,
     CurrentLayerContract currentLayerContract)
 {
     _userInfoContract     = userInfoContract;
     _currentLayerContract = currentLayerContract;
 }
Exemplo n.º 4
0
        private async Task ImportContactsTask()
        {
            var contacts = await _phoneContactService.GetAllContactsAsync();

            ContactSearchRequestFriends.Clear();
            foreach (var c in contacts)
            {
                if (String.IsNullOrEmpty(c.PhoneNumber))
                {
                    continue;
                }
                string formattedPhone = string.Empty;
                foreach (char pc in c.PhoneNumber)
                {
                    if (Char.IsDigit(pc))
                    {
                        formattedPhone += pc;
                    }
                }
                if (formattedPhone.Length != 10)
                {
                    continue;
                }
                var res = await _requestService.GetAsync <PhoneContactSearchContract>("api/PhoneContactSearch/" + formattedPhone);

                if (res.Found &&
                    !String.IsNullOrEmpty(res.UserName) &&
                    !String.IsNullOrEmpty(res.UserId) &&
                    !ContactSearchRequestFriends.Any(cs => cs.UserId.Equals(res.UserId)) &&
                    !MutualFriends.Any(cs => cs.UserId.Equals(res.UserId)) &&
                    !PendingFriends.Any(cs => cs.UserId.Equals(res.UserId)) &&
                    !InitiatedRequestFriends.Any(cs => cs.UserId.Equals(res.UserId)))
                {
                    var uic = new UserInfoContract()
                    {
                        Id          = res.UserId,
                        UserName    = res.UserName,
                        FirstName   = c.FirstName,
                        LastName    = c.LastName,
                        PhoneNumber = formattedPhone
                    };
                    var fvcm = new FriendViewCellModel(uic,
                                                       DateTime.Now,
                                                       FriendRequestType.Normal,
                                                       FriendStatus.FoundInContactSearch);
                    ContactSearchRequestFriends.Add(fvcm);
                }
            }
        }
 public FriendViewCellModel(
     UserInfoContract userInfo,
     DateTime timeStamp,
     FriendRequestType type,
     FriendStatus status)
 {
     UserId      = userInfo.Id;
     UserName    = userInfo.UserName;
     FirstName   = userInfo.FirstName;
     LastName    = userInfo.LastName;
     Gender      = userInfo.Gender;
     PhoneNumber = userInfo.PhoneNumber;
     Email       = userInfo.Email;
     TimeStamp   = timeStamp;
     RequestType = type;
     Status      = status;
 }
        public async Task <IActionResult> GetUserInfo([FromRoute] string id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var target           = _httpContextAccessor.CurrentUserId();
            var friendPermission = await _context.FriendRequests
                                   .SingleOrDefaultAsync(s => s.TargetId.Equals(target) &&
                                                         s.InitiatorId.Equals(id));

            if (friendPermission == null)
            {
                return(NotFound());
            }
            var user = await _context.ApplicationUsers
                       .SingleOrDefaultAsync(s => s.Id.Equals(id));

            if (user == null)
            {
                return(NotFound());
            }
            var contract = new UserInfoContract()
            {
                Id          = user.Id,
                UserName    = user.UserName,
                FirstName   = user.FirstName,
                LastName    = user.LastName,
                DateOfBirth = user.DateOfBirth,
                Gender      = user.Gender,
                AccountType = user.AccountType,
                PhoneNumber = user.PhoneNumber,
                Email       = user.Email
            };

            return(Ok(contract));
        }
        private async Task RegisterAsync()
        {
            var data = new UserInfoContract();

            try
            {
                var result = await _requestService.PostAsync <UserInfoContract, bool>("api/Registration", data);

                if (result)
                {
                    _navigationService.NavigateToLogin();
                }
                else
                {
                    ResultMessage = "Registration process failed. Please verify information provided.";
                    //await _dialogService.DisplayAlertAsync("Registration Failed", "Registration process failed. Please verify information provided.", "OK");
                }
            }
            catch (Exception ex)
            {
                //await _dialogService.DisplayAlertAsync(ex.Message, ex.StackTrace, "OK");
                ResultMessage = ex.Message + "\n" + ex.StackTrace;
            }
        }
Exemplo n.º 8
0
        private async Task SortDataAsync()
        {
            _userSelf = await _requestService.GetAsync <UserInfoContract>("api/UserInfoSelf");

            ContactSearchRequestFriends.Clear();
            MutualFriends.Clear();
            PendingFriends.Clear();
            InitiatedRequestFriends.Clear();

            var entire = await _friendRequestService.GetAllFriendRequestsAsync();

            var initiated = entire.Where(f => f.InitiatorId.Equals(_userSelf.Id) &&
                                         !f.TargetId.Equals(_userSelf.Id)).ToList();
            var targeted = entire.Where(f => f.TargetId.Equals(_userSelf.Id) &&
                                        !f.InitiatorId.Equals(_userSelf.Id)).ToList();

            // first scan through inbound requests,
            // if there is also an initiated request, becomes mutual,
            // otherwise, it is a pending request
            foreach (var req in targeted)
            {
                var initiatorInfo = await _userInfoService.GetUserInfoAsync(req.InitiatorId);

                if (initiated.Any(f => f.TargetId.Equals(req.InitiatorId)))
                {
                    MutualFriends.Add(new FriendViewCellModel(initiatorInfo,
                                                              req.TimeStamp,
                                                              req.Type ?? FriendRequestType.Normal,
                                                              FriendStatus.Mutual));
                }
                else
                {
                    PendingFriends.Add(new FriendViewCellModel(initiatorInfo,
                                                               req.TimeStamp,
                                                               req.Type ?? FriendRequestType.Normal,
                                                               FriendStatus.PendingRequest));
                }
            }
            // scan through the initiated requests,
            // ignoring requests that have a matching target record,
            // these should have already been placed into mutual
            foreach (var req in initiated)
            {
                if (!targeted.Any(f => f.InitiatorId.Equals(req.TargetId)))
                {
                    var targetInfo = await _userInfoService.GetUserInfoAsync(req.TargetId);

                    InitiatedRequestFriends.Add(new FriendViewCellModel(targetInfo,
                                                                        req.TimeStamp,
                                                                        req.Type ?? FriendRequestType.Normal,
                                                                        FriendStatus.Initiated));
                }
            }
            Grouped.Clear();
            GroupedFriendModel csg = new GroupedFriendModel()
            {
                LongName = "Your Contacts", ShortName = "C"
            };

            if (_includeImportedContacts)
            {
                foreach (var mv in ContactSearchRequestFriends.OrderBy(m => m.FirstAndLastName))
                {
                    csg.Add(mv);
                }
            }
            GroupedFriendModel pg = new GroupedFriendModel()
            {
                LongName = "Pending Friend Requests", ShortName = "P"
            };

            foreach (var pv in PendingFriends.OrderBy(m => m.FirstAndLastName))
            {
                pg.Add(pv);
            }
            GroupedFriendModel mg = new GroupedFriendModel()
            {
                LongName = "Mutual Friends", ShortName = "M"
            };

            foreach (var mv in MutualFriends.OrderBy(m => m.FirstAndLastName))
            {
                mg.Add(mv);
            }
            GroupedFriendModel ig = new GroupedFriendModel()
            {
                LongName = "Waiting for Response", ShortName = "W"
            };

            foreach (var iv in InitiatedRequestFriends.OrderBy(m => m.FirstAndLastName))
            {
                ig.Add(iv);
            }
            if (_includeImportedContacts)
            {
                Grouped.Add(csg);
            }
            Grouped.Add(pg);
            Grouped.Add(mg);
            Grouped.Add(ig);
        }