Exemplo n.º 1
0
        public async Task <User> SaveUserCredentials(string token, string password)
        {
            // Get user for a given token
            var user = this.GetUserByEmailConfirmationToken(token);

            // Update email address
            user.UpdateEmailAddress(user.NewEmail);

            // Save changes
            _users.Update(user);

            // Check whether user marked as legal officer
            if (user.IsIntroducedAsLegalOfficer)
            {
                // Get organisation
                var organization = _organisations.FirstOrDefault(i => i.ID == user.OrganizationID.Value);

                // Get legal officers for organisation
                var legalOfficers = _users.Where(i => i.OrganizationID == user.OrganizationID.Value)
                                    .Where(i => i.IsActive == true && i.IsIntroducedAsLegalOfficer == true && i.IsVerifiedAsLegalOfficer == true);

                var userDetailsLink = _urls.ToOrganisationUsers(organization.ID);
                // Check whether legal officers found
                if (!legalOfficers.Any())
                {
                    // Get urls
                    var orgDetailsLink = _urls.ToOrganisationDetails(organization.ID);

                    // Notify admin about new organisation
                    _notifications.Admin.NewOrganizationInBackground(user.Name, organization.Name,
                                                                     userDetailsLink, orgDetailsLink);
                }

                // Notify about new legal officer
                _notifications.Admin.NewLegalOfficerInBackground(userDetailsLink, organization.Name);
            }

            // Add user to Identity Server
            var idsUser = await _identities.CreateUser(user.Email, password, user.Name, user.Phone);

            // Map IDS user to DL user database by id
            user.UserID = idsUser.Id;

            // Save changes
            _users.Update(user);
            return(user);
        }