コード例 #1
0
ファイル: UsersModule.cs プロジェクト: GuMiner/napack
        public static UserSecret AssignSecretsAndSendVerificationEmail(UserIdentifier user)
        {
            UserSecret secret = UserSecret.CreateNewSecret();

            user.Reset(UserIdentifier.ComputeUserHash(secret.Secrets));

            Global.EmailManager.SendVerificationEmail(user);
            return(secret);
        }
コード例 #2
0
ファイル: UserSecret.cs プロジェクト: GuMiner/napack
        public static UserSecret CreateNewSecret()
        {
            UserSecret secret = new UserSecret();

            for (int i = 0; i < UserSecret.SecretCount; i++)
            {
                secret.Secrets.Add(Guid.NewGuid());
            }

            return(secret);
        }
コード例 #3
0
ファイル: UsersModule.cs プロジェクト: GuMiner/napack
        public UsersModule()
            : base("/users")
        {
            // Generates a random series of user identifiers, returning them to the user.
            Post["/"] = parameters =>
            {
                UserIdentifier user = SerializerExtensions.Deserialize <UserIdentifier>(this.Context);

                Global.EmailManager.ValidateUserEmail(user.Email);
                UserSecret secret = AssignSecretsAndSendVerificationEmail(user);
                Global.NapackStorageManager.AddUser(user);

                logger.Info($"Assigned user {user.Email} a hash and secrets, and attempted to send a validation email.");
                return(this.Response.AsJson(new Common.UserSecret()
                {
                    UserId = user.Email,
                    Secrets = secret.Secrets
                }));
            };

            // Confirms a user's registration.
            Patch["/"] = parameters =>
            {
                UserIdentifier user = SerializerExtensions.Deserialize <UserIdentifier>(this.Context);
                Global.EmailManager.ValidateUserEmail(user.Email);

                UserIdentifier serverSideUser = Global.NapackStorageManager.GetUser(user.Email);
                if (!serverSideUser.EmailConfirmed && user.EmailVerificationCode == serverSideUser.EmailVerificationCode)
                {
                    serverSideUser.EmailConfirmed = true;
                }

                Global.NapackStorageManager.UpdateUser(serverSideUser);

                return(this.Response.AsJson(new
                {
                    UserId = user.Email,
                    EmailValidated = serverSideUser.EmailConfirmed
                }));
            };

            Delete["/"] = parameters =>
            {
                UserIdentifier user = SerializerExtensions.Deserialize <UserIdentifier>(this.Context);
                UserIdentifier.VerifyAuthorization(this.Request.Headers.ToDictionary(hdr => hdr.Key, hdr => hdr.Value), Global.NapackStorageManager, new List <string> {
                    user.Email
                });
                return(DeleteUser(this.Response, user));
            };
        }