コード例 #1
0
ファイル: Index.razor.cs プロジェクト: bgkyer/Chat
        private async Task ReceivedWelcomeAsync(WelcomeNotification welcome)
        {
            LogInfo($"Received Welcome: UserId={welcome.UserId}, UserName={welcome.UserName}");

            // update application state
            UserId   = welcome.UserId;
            UserName = welcome.UserName;
            State    = ConnectionState.Connected;

            // update list of channels
            Channels = welcome.Channels;

            // TODO: retrieve active channel from local storage
            const string channelIdConst = "General";

            // add all messages for 'General' channel
            IEnumerable <MessageRecord> messages = new List <MessageRecord>();
            var users = welcome.Users.ToDictionary(user => user.UserId);

            if (welcome.ChannelMessages?.TryGetValue(channelIdConst, out messages) ?? false)
            {
                Messages.AddRange(messages.Select(message => new UserMessageNotification {
                    UserId    = message.UserId,
                    UserName  = users[message.UserId].UserName,
                    ChannelId = channelIdConst,
                    Text      = message.Message,
                    Timestamp = message.Timestamp
                }));
            }

            // update user interface
            StateHasChanged();
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,IsViewed,Created,SenderId,RecipientId")] WelcomeNotification welcomeNotification)
        {
            if (id != welcomeNotification.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(welcomeNotification);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WelcomeNotificationExists(welcomeNotification.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RecipientId"] = new SelectList(_context.Users, "Id", "Id", welcomeNotification.RecipientId);
            ViewData["SenderId"]    = new SelectList(_context.Users, "Id", "Id", welcomeNotification.SenderId);
            return(View(welcomeNotification));
        }
コード例 #3
0
 public void WhenCreatedWithNullArgumentsTest()
 {
     obj = new WelcomeNotification(null);
     Assert.IsNull(obj.Data.Sender);
     Assert.IsNull(obj.Data.Receiver);
     Assert.IsNotNull(obj.Sender.Data);
     Assert.IsNotNull(obj.Receiver.Data);
 }
コード例 #4
0
        private static WelcomeNotificationView create(WelcomeNotification o)
        {
            var v = new WelcomeNotificationView();

            setCommonValues(v, o?.Data?.ID, o?.Data?.Message, o?.Data?.SenderId, o?.Data?.ReceiverId,
                            o?.Data?.IsSeen, o?.Data?.ValidFrom, o?.Data?.ValidTo);
            return(v);
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,IsViewed,Created,SenderId,RecipientId")] WelcomeNotification welcomeNotification)
        {
            if (ModelState.IsValid)
            {
                _context.Add(welcomeNotification);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RecipientId"] = new SelectList(_context.Users, "Id", "Id", welcomeNotification.RecipientId);
            ViewData["SenderId"]    = new SelectList(_context.Users, "Id", "Id", welcomeNotification.SenderId);
            return(View(welcomeNotification));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Email,CompanyToken,InviteDate,IsValid,CompanyId,InvitorId,InviteeId")] Invite invite, string CompanyName, string Role, int projectId)
        {
            if (!(await _roleService.IsUserInRoleAsync(await _userManager.GetUserAsync(User), Roles.DemoUser.ToString())))
            {
                if (ModelState.IsValid)
                {
                    var     loginUser = (await _userManager.GetUserAsync(User));
                    Company company   = new Company();
                    if (await _userManager.IsInRoleAsync(loginUser, Roles.Admin.ToString()))
                    {
                        company = new Company
                        {
                            Name        = CompanyName,
                            Description = $"This is a temporary description for Company: {CompanyName}, you can change this description anytime."
                        };
                        await _context.Company.AddAsync(company);

                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        company = await _context.Company.FirstOrDefaultAsync(c => c.Id == loginUser.CompanyId);
                    }

                    invite.CompanyToken = Guid.NewGuid();
                    invite.CompanyId    = company.Id;
                    var        number_of_user_on_system = _context.Users.ToList().Count + 1;
                    CustomUser newUser = new CustomUser
                    {
                        FirstName      = "Invite",
                        LastName       = $"User #{number_of_user_on_system}",
                        UserName       = invite.Email,
                        Email          = invite.Email,
                        EmailConfirmed = true,
                        CompanyId      = company.Id
                    };
                    try
                    {
                        var newUserFind = await _userManager.FindByEmailAsync(newUser.Email);

                        if (newUserFind == null)
                        {
                            var result = await _userManager.CreateAsync(newUser, "Abc123!");

                            if (result.Succeeded)
                            {
                                string returnUrl = null;
                                returnUrl ??= Url.Content("~/");
                                var code        = invite.CompanyToken;
                                var callbackUrl = Url.Action(
                                    "AcceptInvite",
                                    "Tickets",
                                    values: new { userId = newUser.Id, code },
                                    protocol: Request.Scheme);

                                await _emailSender.SendEmailAsync(newUser.Email, "Invite Email From Lan's Bug Tracker",
                                                                  $"<h1>You received a invite ticket from Lan's Bug Tracker</h1> <br> <a style='background-color: #555555;border: none;color: white;padding: 15px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;' href='{HtmlEncoder.Default.Encode(callbackUrl)}'>Clicking here to join our software.</a>  <br> <h3>Your UserName is: {newUser.Email} </h3><br> <h3>Your Password is: Abc123!</h3>");

                                if (await _userManager.IsInRoleAsync(loginUser, Roles.Admin.ToString()))
                                {
                                    await _userManager.AddToRoleAsync(newUser, Roles.ProjectManager.ToString());
                                }
                                else if (await _userManager.IsInRoleAsync(loginUser, Roles.ProjectManager.ToString()))
                                {
                                    await _userManager.AddToRoleAsync(newUser, _context.Roles.FirstOrDefault(r => r.Id == Role).Name);
                                }
                                else
                                {
                                    await _userManager.AddToRoleAsync(newUser, Roles.NewUser.ToString());
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("*************  ERROR  *************");
                        Debug.WriteLine("Error Create User For Invite Ticket.");
                        Debug.WriteLine(ex.Message);
                        Debug.WriteLine("***********************************");
                        throw;
                    }
                    var admin = await _userManager.FindByEmailAsync("*****@*****.**");


                    if (await _userManager.IsInRoleAsync(loginUser, Roles.Admin.ToString()))
                    {
                        var     number_of_project_on_system = _context.Project.Count() + 1;
                        Project project = new Project
                        {
                            Name        = $"Project Example #{number_of_project_on_system}",
                            Description = $"This is your project Example #{number_of_project_on_system}, you can change anything in this project anytime you want",
                            Created     = DateTime.Now,
                            CompanyId   = company.Id
                        };
                        await _context.Project.AddAsync(project);

                        await _context.SaveChangesAsync();

                        await _projectService.AddUserToProjectAsync(newUser.Id, project.Id);
                    }
                    else if (await _userManager.IsInRoleAsync(loginUser, Roles.ProjectManager.ToString()))
                    {
                        if (projectId != 0)
                        {
                            if ((await _projectService.ProjectManagerOnProjectAsync(projectId)).Id == loginUser.Id)
                            {
                                await _projectService.AddUserToProjectAsync(newUser.Id, projectId);
                            }
                        }
                    }
                    if (!await _userManager.IsInRoleAsync(loginUser, Roles.Admin.ToString()))
                    {
                        string adminEmail = admin.Email;
                        string subject    = "New User Have Been Invited";
                        string message    = $"{loginUser.FullName} just send a Invite Ticket to {invite.Email}";

                        await _emailSender.SendEmailAsync(adminEmail, subject, message);

                        await _context.SaveChangesAsync();
                    }
                    //notification for new user
                    WelcomeNotification welcomenotification = new WelcomeNotification
                    {
                        Name        = "Welcome To The Bug Tracker",
                        Description = $"You have been Invited to the bug tracker service by {loginUser.FullName}. Your role is: {(await _roleService.ListUserRoleAsync(newUser)).First()}. Please contact our admin or project manager ({loginUser.FullName}) by the inbox system.Or, you can start create new ticket and start working on it. You can change your name in profile setting under your name in the vertical Nav bar.",
                        Created     = DateTime.Now,
                        SenderId    = (admin).Id,
                        RecipientId = newUser.Id
                    };
                    await _context.WelcomeNotification.AddAsync(welcomenotification);

                    await _context.SaveChangesAsync();

                    //noification for admin
                    WelcomeNotification welcomenotification2 = new WelcomeNotification
                    {
                        Name        = "New invite ticket has been sent",
                        Description = $"{loginUser.FullName} just send a Invite Ticket to {invite.Email}",
                        Created     = DateTime.Now,
                        SenderId    = (admin).Id,
                        RecipientId = (admin).Id
                    };
                    await _context.WelcomeNotification.AddAsync(welcomenotification2);

                    await _context.SaveChangesAsync();

                    //noification for person who send invite ticket
                    WelcomeNotification welcomenotification3 = new WelcomeNotification
                    {
                        Name        = "New invite ticket has been sent",
                        Description = $"You just send a Invite Ticket to {invite.Email}",
                        Created     = DateTime.Now,
                        SenderId    = (admin).Id,
                        RecipientId = loginUser.Id
                    };
                    await _context.WelcomeNotification.AddAsync(welcomenotification3);

                    await _context.SaveChangesAsync();

                    invite.InvitorId  = loginUser.Id;
                    invite.InviteeId  = newUser.Id;
                    invite.InviteDate = DateTime.Now;
                    invite.IsValid    = true;
                    _context.Add(invite);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("DemoUser", "Projects"));
        }
コード例 #7
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new CustomUser {
                    UserName = Input.Email, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName, CompanyId = _context.Company.FirstOrDefault(c => c.Name == "New User Company").Id
                };

                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    await _roleService.AddUserToRoleAsync(user, Roles.NewUser.ToString());

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    var admin = await _userManager.FindByEmailAsync("*****@*****.**");

                    WelcomeNotification welcomenotification = new WelcomeNotification
                    {
                        Name        = "Welcome To The Bug Tracker",
                        Description = $"Hello {user.FullName} You have created a new account in my bug tracker service. Your role is New User and you are working at {_context.Company.FirstOrDefault(c => c.Id == user.CompanyId).Name}. Please wait our admin or project manager assign you a higher role in the system. You can contact our staff by the inbox system. My recommendation is to Login as a Demo User, you can see everything my Bug Tracker can do..",
                        Created     = DateTime.Now,
                        SenderId    = (admin).Id,
                        RecipientId = user.Id
                    };
                    await _context.WelcomeNotification.AddAsync(welcomenotification);

                    await _context.SaveChangesAsync();

                    WelcomeNotification welcomenotification2 = new WelcomeNotification
                    {
                        Name        = "New Account have been created",
                        Description = $"A new user have been created on {DateTime.Now} with Full Name is: {user.FullName} and Email is: {user.Email}",
                        Created     = DateTime.Now,
                        SenderId    = (admin).Id,
                        RecipientId = (admin).Id
                    };
                    await _context.WelcomeNotification.AddAsync(welcomenotification2);

                    await _context.SaveChangesAsync();


                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
コード例 #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //NotifBildirim.Text = "llllllllllllll";
        //NotifBildirim.Show();

        //if (Session["YeniChatTalebiVar"] != null)
        //{
        //    if (Session["YeniChatTalebiVar"].ToString() == "E")
        //    {
        //        //this.Page.ClientScript.RegisterClientScriptBlock(GetType(), "Test", "YeniChatTalebiIcinRadWindowuAc();");
        //        /*
        //        RadWindow1.Width = 800;
        //        RadWindow1.Height = 600;
        //        RadWindow1.Modal = true;

        //        RadWindow1.Skin = "Simple";
        //        RadWindow1.VisibleOnPageLoad = true;
        //        RadWindow1.Visible = true;
        //        RadWindow1.Title = "Paket Kapsamına Alma";
        //        RadWindowManager1.Windows.Add(RadWindow1);
        //        RadWindow1.NavigateUrl = "~/UserControls/Pages/ChatRoom.aspx?RoomId=1";
        //         */
        //    }
        //}
        if (!IsPostBack)
        {
            EFDal ed = new EFDal();
            if (Context.User.Identity.IsAuthenticated)
            {
                if (Session["BuOturumdaImzaUyarisiVerme"] == null)
                {
                    if (
                        ed.PersonelinImzasınıBekleyenBelgeleriDon(ed.UserNamedenPersonelUNDon(Context.User.Identity.Name))
                        .Tables[0].Rows.Count > 0)
                    {
                        LabelName.Text = "Hoşgeldiniz Sn. <em>" + ed.UserNamedenTamIsimDon(Context.User.Identity.Name) +
                                         "</em> ! Aşağıdaki fonksiyonlardan birini seçebilirsiniz... ";
                        WelcomeNotification.Show();
                    }
                }

                lblWellcome.Text = "Hoşgeldiniz " + Context.User.Identity.Name;

                lnkLoginStatus.Visible   = true;
                lblWellcome.Visible      = true;
                Login.Visible            = false;
                div1.Visible             = false;
                div3.Visible             = false;
                div4.Visible             = false;
                pnlMenu.Visible          = true;
                boxGelismisArama.Visible = true;
            }
            else
            {
                divOnlineUsers.Visible   = false;
                boxGelismisArama.Visible = false;
            }
            //else if (Session["DisaridanGelenFirmaId"] != null)
            if (Session["DisaridanGelenFirmaId"] != null)
            {
                int FirmaId = int.Parse(Session["DisaridanGelenFirmaId"].ToString());
                //EFDal ed=new EFDal();
                string FirmaAdi = ed.FirmaIddenFirmaAdiDon(FirmaId);
                lblWellcome.Text       = "Hoşgeldiniz " + FirmaAdi;
                lnkLoginStatus.Visible = true;
                lblWellcome.Visible    = true;
                Login.Visible          = false;
                div1.Visible           = false;
                div3.Visible           = false;
                div4.Visible           = false;
            }

            string url = HttpContext.Current.Request.Url.AbsoluteUri;
            if (url.IndexOf("KalibrasyonForumu") > 0 || url.IndexOf("allForums") > 0 || url.IndexOf("MusteriAnketi") > 0)
            {
                div1.Visible = false;
                div3.Visible = false;
                div4.Visible = false;
            }
            SonForumKonulariBagla();
        }
        //else
        //{
        //    if (Context.User.Identity.IsAuthenticated)
        //    {
        //        lnkLoginStatus.Visible = true;
        //        lblWellcome.Visible = true;
        //        lblWellcome.Text = "Hoşgeldiniz "+Context.User.Identity.Name;
        //    }
        //}
    }